linux 如何修复npm错误EACCES:拒绝许可?

esbemjvw  于 2023-06-21  发布在  Linux
关注(0)|答案(2)|浏览(182)

我试着开始一个项目,安装npm install -g pnpm作为一个要求,我尝试了npm安装,但它确实工作。但npm install -g pnpm显示错误如下;下面是终端!

npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/pnpm/bin/pnpm.cjs
npm ERR! dest /usr/bin/pnpm
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/pnpm/bin/pnpm.cjs' -> '/usr/bin/pnpm'
npm ERR!  [OperationalError: EACCES: permission denied, symlink '../lib/node_modules/pnpm/bin/pnpm.cjs' -> '/usr/bin/pnpm'] {
npm ERR!   cause: [Error: EACCES: permission denied, symlink '../lib/node_modules/pnpm/bin/pnpm.cjs' -> '/usr/bin/pnpm'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'symlink',
npm ERR!     path: '../lib/node_modules/pnpm/bin/pnpm.cjs',
npm ERR!     dest: '/usr/bin/pnpm'
npm ERR!   },
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/pnpm/bin/pnpm.cjs',
npm ERR!   dest: '/usr/bin/pnpm'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
3qpi33ja

3qpi33ja1#

1.备份您的计算机。
1.在命令行上,在主目录中,为全局安装创建一个目录:

mkdir ~/.npm-global

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

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

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

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

1.在命令行中,更新系统变量:

source ~/.profile

1.要测试新配置,请在不使用sudo的情况下全局安装一个软件包:

npm install -g pnpm

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

yks3o0rb

yks3o0rb2#

另一种选择是在硬盘上创建一个新分区,或者如果可能的话创建一个全新的驱动器(在Windows操作系统上为D:\或E:\),并按照我们所知道的方式配置项目-隔离安装的软件包。
虽然全球安装很方便,但由于Mac和PC的安全性越来越高,这些EACCES错误总是会出现。

相关问题