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

 

 

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),
or
  • 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§

Note: This section does not apply to Microsoft Windows.

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.

  1. Back up your computer.
  2. On the command line, in your home directory, create a directory for global installations:
     mkdir ~/.npm-global
    
  3. Configure npm to use the new directory path:
     npm config set prefix '~/.npm-global'
    
  4. In your preferred text editor, open or create a ~/.profile file and add this line:
     export PATH=~/.npm-global/bin:$PATH
    
  5. On the command line, update your system variables:
     source ~/.profile
    
  6. 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
npx: an alternative to running global commands 

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 npm@latest -g

To report bugs or submit feature requests for the docs, please post here. Submit npm issues here.

转载于:https://www.cnblogs.com/lobin/p/10193261.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值