我在 Fedora 30 上安装电子时出错

I have error for install electron on fedora 30

你好,如果我尝试在我的软呢帽 30 上安装电子,我会遇到这个错误

[luisjustin@localhost ~]$ sudo su
[sudo] password for luisjustin: 
[root@localhost luisjustin]# npm install -g electron
/usr/bin/electron -> /usr/lib/node_modules/electron/cli.js

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

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

Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/electron/.electron'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron@5.0.2 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the electron@5.0.2 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!     /root/.npm/_logs/2019-05-30T01_21_04_805Z-debug.log
[root@localhost luisjustin]# 

此link中的日志:https://pastebin.com/q3dSCQVg

您机器上的权限似乎有问题(/usr/lib 目录需要 root 访问权限)。我建议您尝试更改 NPM 全局安装软件包的默认目录。然后你可以尝试运行没有root权限的安装。

试试这个:

  1. 在命令行中,在您的主目录中,为全局安装创建一个目录:

    mkdir ~/.npm-global

  2. 配置 npm 以使用新的目录路径:

    npm config set prefix '~/.npm-global'

  3. 在您首选的文本编辑器中,打开或创建一个 ~/.profile 文件并添加以下行:

    export PATH=~/.npm-global/bin:$PATH

  4. 在命令行中,更新您的系统变量:

    source ~/.profile

  5. 要测试您的新配置,请在不使用 sudo 的情况下全局安装包:

    npm install -g electron

礼貌: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally