使用命令 npm install -g yarn 安装 Yarn 时,出现错误

Posted

技术标签:

【中文标题】使用命令 npm install -g yarn 安装 Yarn 时,出现错误【英文标题】:When installing Yarn with the command npm install -g yarn, I get a bug 【发布时间】:2021-12-16 01:05:30 【问题描述】:
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/andybod/.npm/_logs/2021-11-01T08_46_14_576Z-debug.log

【问题讨论】:

【参考方案1】:

您尝试写入您的用户没有此类权限的文件夹 (/usr)

只需为此目的使用 sudo

sudo npm install -g yarn

【讨论】:

以上是关于使用命令 npm install -g yarn 安装 Yarn 时,出现错误的主要内容,如果未能解决你的问题,请参考以下文章

Yarn和npm命令

Yarn和npm命令对比

Yarn和npm命令对比

解决在部署前端Vue框架项目时,使用npm install和yarn install安装插件报错

解决在部署前端Vue框架项目时,使用npm install和yarn install安装插件报错

npm与yarn常用命令对比