npm 命令报权限不足错误 Error EACCES permission denied

在使用 npm 命令安装组件的时候,经常会报 权限不足 的错误:Error: EACCES: permission denied ,虽然用 sudo 可以解决问题,但都只是暂时的;

错误信息

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
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 (though this is not recommended).

npm ERR! A complete log of this run can be found in:

解决方法

  1. 重装 version manager
  2. 改变 npm 的默认路径

这里我选择了第 2

中文译

创建global安装任务的目录

mkdir ~/.npm-global

配置npm使用新的目录

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

~/.profile文件中增加配置

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

配置文件立即生效

source ~/.profile

重新执行命令

npm install -g xxxx
前端开发

Element UI 使用 Switch 开关组件 Number 数据类型

2019-11-12 10:20:17

网站记录

WordPress 修正定时任务发布文章失败方法

2020-6-30 11:40:20

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索