我正在尝试在我的本地机器 (centOS) 上完成 React 教程
我跑了
sudo npm install -g create-react-app
运行该命令后出现以下错误
npm ERR! Linux 3.10.0-514.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "create-react-app"
npm ERR! node v6.10.3
npm ERR! npm v3.10.10
npm ERR! path /tmp/npm-1422-84cdbe70/registry.npmjs.org/tar/-/tar-2.2.1.tgz
npm ERR! code EPERM
npm ERR! errno -1
npm ERR! syscall open
npm ERR! Error: EPERM: operation not permitted, open '/tmp/npm- 1422-84cdbe70/registry.npmjs.org/tar/-/tar-2.2.1.tgz' while getting shasum for /tmp/npm-1422-84cdbe70/registry.npmjs.org/tar/-/tar-2.2.1.tgz
npm ERR! From: https://registry.npmjs.org/tar/-/tar-2.2.1.tgz
npm ERR! at Error (native)
npm ERR! { Error: EPERM: operation not permitted, open '/tmp/npm-1422-84cdbe70/registry.npmjs.org/tar/-/tar-2.2.1.tgz' while getting shasum for /tmp/npm-1422-84cdbe70/registry.npmjs.org/tar/-/tar-2.2.1.tgz
npm ERR! From: https://registry.npmjs.org/tar/-/tar-2.2.1.tgz
npm ERR! at Error (native)
npm ERR! errno: -1,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'open',
npm ERR! path: '/tmp/npm-1422-84cdbe70/registry.npmjs.org/tar/-/tar-2.2.1.tgz',
npm ERR! parent: 'tar-pack' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
我尝试进入目录并解压缩 .tgz 文件并更改一些权限,但没有任何效果。我在网上关注了一些类似问题的解决方案,但仍然没有成功。
我也跑了
npm cache clear
谁能解释为什么会这样?有什么建议吗?
最佳答案
运行 npm cache clear
甚至 npm cache clear -f
并不总能清除所有缓存。
有时您应该手动删除缓存文件。 为此,请转到默认的 NPM 缓存文件夹并删除其内容:
默认:Linux 上的~/.npm
,Windows 上的%AppData%/npm-cache
。
然后您可以尝试使用 npm install -g
安装您想要的包。
请避免使用 sudo npm install -g
因为你可能会弄乱 npm 权限。而是将权限更改为 npm 的默认目录,或者将 npm 的默认目录更改为其他目录。更多细节在这里:
https://docs.npmjs.com/getting-started/fixing-npm-permissions
警告:如果 npm 的默认路径只是 /usr
,更改目录权限将是有害的。
关于node.js - npm-EPERM : operation not permitted on Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44331168/