英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论