安装electron,与安装失败问题的解决方案

安装electron,与安装失败问题的解决方案

按照说明文档运行

sudo npm install -g electron

安装失败,提示:

/usr/local/bin/electron -> /usr/local/lib/node_modules/electron/cli.js

> electron@1.6.11 postinstall /usr/local/lib/node_modules/electron
> node install.js

/usr/local/lib/node_modules/electron/install.js:47
  throw err
  ^

Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/electron/electron-tmp-download-95371-1500432657864'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron@1.6.11 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the electron@1.6.11 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/zhaoyifeng/.npm/_logs/2017-07-19T02_50_59_571Z-debug.log

经过查询,如下命令可正常安装

sudo npm install -g electron --unsafe-perm=true --allow-root

—unsafe-perm:默认为false,如果为true则使用root用户安装,默认为非root用户安装
—allow-root: 允许root

另外,由于伟大的gfw问题,可能安装进度过于缓慢,那么我们需要添加国内镜像地址,即可安装成功。

sudo npm install -g electron --unsafe-perm=true --allow-root --registry=https://registry.npm.taobao.org

Password:
/usr/local/bin/electron -> /usr/local/lib/node_modules/electron/cli.js

> electron@1.6.11 postinstall /usr/local/lib/node_modules/electron
> node install.js

+ electron@1.6.11
updated 11 packages in 102.746s

摄影爱好者,全栈工程师,游戏玩家,积木苦手,超穷手办收藏爱好者

发表评论