npm install 权限问题
Posted lobin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了npm install 权限问题相关的知识,希望对你有一定的参考价值。
npm ERR! Error: EACCES: permission denied, access ‘/Users/Lobin/work/note-vue/node_modules/@babel/highlight/node_modules/chalk‘ npm ERR! { Error: EACCES: permission denied, access ‘/Users/Lobin/work/note-vue/node_modules/@babel/highlight/node_modules/chalk‘ npm ERR! stack: ‘Error: EACCES: permission denied, access ‘/Users/Lobin/work/note-vue/node_modules/@babel/highlight/node_modules/chalk‘‘, npm ERR! errno: -13, npm ERR! code: ‘EACCES‘, npm ERR! syscall: ‘access‘, npm ERR! path: ‘/Users/Lobin/w
解决方案:官方链接
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
If you see an EACCES
error when you try to install a package globally, you can either:
- Reinstall npm with a node version manager (recommended),
- Manually change npm’s default directory
Reinstall npm with a node version manager
This is the best way to avoid permissions issues. To reinstall npm with a node version manager, follow the steps in “Downloading and installing Node.js and npm”. You do not need to remove your current version of npm or Node.js before installing a node version manager.
Manually change npm’s default directory
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.
- Back up your computer.
- On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global
- Configure npm to use the new directory path:
npm config set prefix ‘~/.npm-global‘
- In your preferred text editor, open or create a
~/.profile
file and add this line:export PATH=~/.npm-global/bin:$PATH
- On the command line, update your system variables:
source ~/.profile
- To test your new configuration, install a package globally without using
sudo
:npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don’t want to modify ~/.profile
):
NPM_CONFIG_PREFIX=~/.npm-global
If you are using npm version 5.2 or greater, you may want to consider npx as an alternative way to run global commands, especially if you only need a command occasionally. For more information, see this article about npx.
The current stable version of npm is here. To upgrade, run: npm install [email protected] -g
To report bugs or submit feature requests for the docs, please post here. Submit npm issues here.
以上是关于npm install 权限问题的主要内容,如果未能解决你的问题,请参考以下文章
jenkins npm install WARN checkPermissions Missing write access 权限问题
docker image 上的 npm global install 没有访问权限错误
当我执行 npm install 时,Git Clone 的权限被拒绝
npm install -g less 不起作用:EACCES:权限被拒绝
linux 下 root 权限执行 npm install 报错:Error:EACCES:permission denied ‘xxx‘?