node.js 在 mac 中缺少对 /usr/local/lib/node_modules 的写访问权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54802330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:56:59  来源:igfitidea点击:

Missing write access in mac to /usr/local/lib/node_modules

node.jsangularangular-clinode-modules

提问by Kundan Kumar Mourya

I am trying to install angular cli but it's show me Missing write access to /usr/local/lib/node_modules so, how can I fix it in my mac i try it may time but, not getting exact answer

我正在尝试安装 angular cli,但它显示我缺少对 /usr/local/lib/node_modules 的写访问权限,因此,如何在我的 mac 中修复它,我可能会尝试,但没有得到确切的答案

 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).

回答by jeduard

Run these commands in a terminal window:

在终端窗口中运行这些命令:

sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules

回答by Dimitri

I had this issue, I could fixed it by calling sudo on every global install. I wasn't ok with that.

我遇到了这个问题,我可以通过在每次全局安装时调用 sudo 来修复它。我不同意。

I followed the n package installationadvices to be able to install npm packages without sudo.

我遵循了n 包安装建议,以便能够在没有 sudo 的情况下安装 npm 包。

sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share

Answer of @jeduard didn't work for me.

@jeduard 的回答对我不起作用。

回答by P.Sav

Same problem. I reinstalled the latest version of node via https://nodejs.org/en/download/instead of using terminal. This resolved the issue.

同样的问题。我通过https://nodejs.org/en/download/而不是使用终端重新安装了最新版本的节点。这解决了问题。

回答by RCross

If you're reallyblocked on installing NPM modules globally (e.g. on some corporate laptop), you could just install them all in a single local folder somewhere and then add the path to node_modules/.bin/ to your PATH environment.

如果您真的无法全局安装 NPM 模块(例如在某些公司笔记本电脑上),您可以将它们全部安装在某个地方的单个本地文件夹中,然后将 node_modules/.bin/ 的路径添加到您的 PATH 环境中。

回答by GProxy

I had a similar issue when trying to install React -- issues with permissions being denied.

我在尝试安装 React 时遇到了类似的问题——权限被拒绝的问题。

This is where SUDO can come in handy, it allows a permitted user to execute a command as the superuser or another user. Think of like "Run as Administrator" on Windows. If you type in the following command, it should allow you to access all of the needed folders with the proper elevated access.

这是 SUDO 可以派上用场的地方,它允许允许的用户以超级用户或其他用户的身份执行命令。想想 Windows 上的“以管理员身份运行”。如果您输入以下命令,它应该允许您使用适当的提升访问权限访问所有需要的文件夹。

sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share

This is also denoted in Dimitri'sanswer: https://stackoverflow.com/a/60791736/3803726

这也在Dimitri 的回答中表示:https: //stackoverflow.com/a/60791736/3803726

回答by larviz27

Try using on the terminal

尝试在终端上使用

su

It'll ask you for the password, then you can run the command above.

它会询问您密码,然后您可以运行上面的命令。