npm安装错误:EACCES:权限被拒绝

huangapple go评论65阅读模式
英文:

npm install Error: EACCES: permission denied

问题

我在新的Linux虚拟机(Debian 11 - Bullseye)上安装了nvm、node和npm。当我运行 which npm 时,显示如下:

/home/user/.nvm/versions/node/v20.4.0/bin/npm

我在 /var 目录下创建了一个名为 test 的文件夹,并在 /var/test 目录下运行了以下命令:

npm install --verbose @wordpress/scripts --save-dev

但是出现了以下错误:

Error: EACCES: permission denied, mkdir '/var/test/node_modules'
npm ERR!  [Error: EACCES: permission denied, mkdir '/var/test/node_modules'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/var/test/node_modules'
npm ERR! }

然后根据这个链接,我执行了以下步骤:

mkdir ~/.npm-global
export NPM_CONFIG_PREFIX=~/.npm-global
export PATH=$PATH:~/.npm-global/bin
echo -e "export NPM_CONFIG_PREFIX=~/.npm-global\nexport PATH=$PATH:~/.npm-global/bin" >> ~/.bashrc

重新启动了终端,然后再次尝试运行 npm install --verbose @wordpress/scripts --save-dev,但仍然出现 Error: EACCES: permission denied, mkdir '/var/test/node_modules' 错误。

请问如何在 /var/test 目录下运行npm install?

英文:

I installed nvm , node and npm on to a new linux VM (debian 11 - bullseye)
When I do which npm , it shows

/home/user/.nvm/versions/node/v20.4.0/bin/npm

I created a test directory in /var

and I ran npm install --verbose @wordpress/scripts --save-dev command from /var/test and got error

 Error: EACCES: permission denied, mkdir '/var/test/node_modules'
npm ERR!  [Error: EACCES: permission denied, mkdir '/var/test/node_modules'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/var/test/node_modules'
npm ERR! }

Then as per this , I did

mkdir ~/.npm-global
export NPM_CONFIG_PREFIX=~/.npm-global
export PATH=$PATH:~/.npm-global/bin
echo -e "export NPM_CONFIG_PREFIX=~/.npm-global\nexport PATH=$PATH:~/.npm-global/bin" >> ~/.bashrc

restarted terminal

and then tried npm install --verbose @wordpress/scripts --save-dev again but I still get Error: EACCES: permission denied, mkdir '/var/test/node_modules'

how can I run npm install from /var/test ?

答案1

得分: 1

你必须给予这个文件夹写入权限

sudo a+w /var/test
英文:

You must give write permission to this folder

sudo a+w /var/test

huangapple
  • 本文由 发表于 2023年7月18日 01:51:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706972.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定