Ubuntu root权限安装electron出错npm ERR! [email protected] postinstall: `node install.js`

安装过程:

安装nodejs

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

安装Electron:

gedit package.json
#把 "name": "electron" 改为 "name": "electron-test", 保存.
# Install as a development dependency
npm install electron --save-dev
# Install the `electron` command globally in your $PATH
sudo npm install electron -g

此时出错:

Error: EACCES: permission denied, mkdtemp '/usr/local/lib/node_modules/electron/electron-download-3a1HyX'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我平时用的就是root账户,不应该是权限不足的问题,没想到是electron不能直接用root账户安装的问题。解决方案在:
https://github.com/npm/npm/issues/17268
只需要把上面最后一句

sudo npm install electron -g

换为

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

就安装完成。测试:

electron --version --no-sandbox
#使用root账户看版本要加上 --no-sandbox

你可能感兴趣的:(Linux,npm,ubuntu,javascript)