注意
本文所述的安装方法对electron的4.1.3,6.1.7有效,对10.1.0无效,10.1.0临时安装方法参见文章底部。
- 安装electron前的准备
从http://www.loongnix.org/index.php/Electron下载所需软件包,
a)将tar包解开,重新压缩成zip包
tar xzf electron_v4.1.3.tar.gz
cd electron_v4.1.3
zip -r electron-v4.1.3-linux-mips64el.zip ./*
mv electron-v4.1.3-linux-mips64el.zip ../
b)执行如下命令,生成文件校验值
sha256sum electron-v4.1.3-linux-mips64el.zip > SHASUMS256.txt-4.1.3
执行完成后打开SHASUMS256.txt-4.1.3,如下:
e461f4158e68c41ed824ba2f59a36079e6ae596d1ad7a8a72d1722b78d251e81 electron-v4.1.3-linux-mips64el.zip
改为如下:
e461f4158e68c41ed824ba2f59a36079e6ae596d1ad7a8a72d1722b78d251e81 *electron-v4.1.3-linux-mips64el.zip
注意:
没更改之前e461f4158e68c41ed824ba2f59a36079e6ae596d1ad7a8a72d1722b78d251e81和electron-v4.1.3-linux-mips64el.zip有两个空格,改完后有一个空格,并有一个*号做分隔符。
c)执行如下脚本,将electron-v4.1.3-linux-mips64el.zip和SHASUMS256.txt-4.1.3放到~/.cache/electron/下
./preinstall.sh
preinstall.sh如下:
#!/usr/bin/env bash
# 在安装electron前的环境设置
electron_path="$HOME/.cache/electron"
if [ ! -d ${electron_path} ]; then
mkdir -p ${electron_path}
fi
electron="electron-v4.1.3-linux-mips64el.zip"
shasums="SHASUMS256.txt-4.1.3"
if [ -f ${electron} -a -f ${shasums} ];then
cp ${electron} ${shasums} ${electron_path}
else
echo "${electron} and ${shasums} doesn't exists"
exit 1
fi
echo "preinstall done"
- 本地安装electron
如果,当前网络不能有效的安装electron
,建议将npm
的镜像源地址修改为国内源
npm config set registry https://registry.npm.taobao.org
- 本地项目安装electron
git clone https://github.com/electron/electron-quick-start.git
cd electron-quick-start/
git checkout remotes/origin/4-x-y
npm install electron@4.1.3
测试electron
是否正确安装:
cd electron-quick-start/
npm start
执行之后,会在本地弹出页面窗口,并显示当前的electron
版本。
表明electron
已经正确安装。
- 全局安装electron
npm install electron@4.1.3 -g
如果提示有诸如access
或permission
的权限问题,请添加--unsafe-perm=true
参数
如下:
npm install electron@4.1.3 -g --unsafe-perm=true
10.1.0安装
由于4和6版本使用的下载模块是electron-download,支持本地cache和本地mirror进行安装,但是到了10.1.0,使用的是electron/get模块安装,不在支持本地cache了。但是可以通过设置如下参数解决10.1.0的安装
Using environment variables for mirror
options
Mirror options can also be specified via the following environment variables:
* `ELECTRON_CUSTOM_DIR` - Specifies the custom directory to download from.
* `ELECTRON_CUSTOM_FILENAME` - Specifies the custom file name to download.
* `ELECTRON_MIRROR` - Specifies the URL of the server to download from if the version is not a nightly version.
* `ELECTRON_NIGHTLY_MIRROR` - Specifies the URL of the server to download from if the version is a nightly version.
问题
- 运行
electron
出现问题
把缓存重新删除,卸载electron
。到解压出来的目录中执行预处理脚本,然后重新安装electron