npm抛出没有sudo的错误

本文翻译自:npm throws error without sudo

I just installed node and npm through the package on nodejs.org and whenever I try to search or install something with npm it throws the following error, unless I sudo the command. 我只是通过nodejs.org上的软件包安装了node和npm,并且每当我尝试使用npm搜索或安装某些东西时,都会抛出以下错误,除非我对命令进行了sudo。 I have a feeling this is a permissions issue? 我觉得这是权限问题? I am already the admin. 我已经是管理员。

npm ERR! Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json'
npm ERR!  { [Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Users/chietala/.npm/-/all/.cache.json' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.2.0
npm ERR! command "node" "/usr/local/bin/npm" "search" "bower"
npm ERR! cwd /Users/chietala
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! path /Users/chietala/.npm/-/all/.cache.json
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/chietala/npm-debug.log
npm ERR! not ok code 0

#1楼

参考:https://stackoom.com/question/15lcI/npm抛出没有sudo的错误


#2楼

This looks like a permissions issue in your home directory. 这看起来像您的主目录中的权限问题。 To reclaim ownership of the .npm directory execute: 要回收.npm目录的所有权, 执行以下操作:

sudo chown -R $(whoami) ~/.npm

#3楼

另外,您将需要在node_modules目录中具有写许可权:

sudo chown -R $USER /usr/local/lib/node_modules

#4楼

I encountered this when installing Recess ( https://github.com/twitter/recess ) to compile my CSS for Bootstrap 3. 我在安装Recess( https://github.com/twitter/recess )来为Bootstrap 3编译我的CSS时遇到了这个问题。

When installing recess: 安装凹槽时:

-npm install recess -g
  1. You need to unlock permissions in your home directory, like Noah says: 您需要解锁home目录中的权限,例如Noah所说:

     sudo chown -R `whoami` ~/.npm 
  2. You also need write permissions to the node_modules directory, like Xilo says, so if it still isn't working, try: 您还需要对node_modules目录的写权限,如Xilo所说,因此,如果它仍然不起作用,请尝试:

     sudo chown -R `whoami` /usr/local/lib/node_modules 
  3. If you are still seeing errors, you may also need to correct /usr/local permissions : 如果仍然看到错误,则可能还需要更正/usr/local权限

     sudo chown -R `whoami` /usr/local 

Please note that as indicated in this post /usr/local/ isn't actually a system dir if you are on a Mac, so, this answer is actually perfectly "safe" for Mac users. 请注意,如本文所述,如果您使用的是Mac,则/usr/local/实际上不是系统目录,因此,对于Mac用户,此答案实际上是“安全的”。 However, if you are on Linux, see Christopher Will 's answer below for a multi-user friendly, system dir safe (but more complex) solution. 但是,如果您使用的是Linux,请参阅下面的Christopher Will的答案,以获取对多用户友好的系统目录安全(但更复杂)的解决方案。


#5楼

I had a similar problem at NPM modules won't install globally without sudo , the issue was that when i installed node i did it with sudo via chris/lea ppa repo . 我在NPM模块上有一个类似的问题, 如果没有sudo将无法在全球范围内安装模块 ,问题是当我安装节点时,我通过chris / lea ppa repo使用sudo进行了安装

My solution was to uninstall node and then install it this way: 我的解决方案是卸载节点,然后以这种方式安装它:

Download latest stable node sources from nodejs.org #in my case node-v0.10.20.tar.gz 从nodejs.org下载最新的稳定节点源#就我而言为node-v0.10.20.tar.gz

tar -zxf node-v0.10.20.tar.gz #uncompress sources tar -zxf node-v0.10.20.tar.gz#解压缩源

cd node-v0.10.20 #enter uncompressed folder cd node-v0.10.20#输入未压缩的文件夹

sudo chown $USER -R /usr/local 须藤chown $ USER -R / usr / local

./configure --prefix=/usr/local && make && make install ./configure --prefix = / usr / local && make &&进行安装

PD: If you don't want to change ownership of the /usr/local folder, you can install it somewhere you already own. PD:如果您不想更改/ usr / local文件夹的所有权,可以将其安装在您已经拥有的位置。 The problem of this approach is that you will have to bind the installation folder with the bash command line so that we can use the node command later on 这种方法的问题是,您将必须将安装文件夹与bash命令行绑定,以便稍后我们可以使用node命令。

mkdir ~/opt mkdir〜/ opt

./configure --prefix=~/opt && make && make install ./configure --prefix =〜/ opt && make &&进行安装

echo 'export PATH=~/opt/bin:${PATH}' >> ~/.bashrc #or ~/.profile or ~/.bash_profile or ~/.zshenv depending on the current Operative System echo'export PATH =〜/ opt / bin:$ {PATH}'>>〜/ .bashrc #or〜/ .profile或〜/ .bash_profile或〜/ .zshenv,具体取决于当前的操作系统

With either of those approaches, you will be able to do the following without using sudo 无论使用哪种方法,都可以在不使用sudo的情况下执行以下操作

npm install -g module_to_install npm install -g module_to_install


#6楼

When you run npm install -g somepackage, you may get an EACCES error asking you to run the command again as root/Administrator. 当您运行npm install -g somepackage时,可能会出现EACCES错误,要求您以root / Administrator身份再次运行命令。 It's a permissions issue. 这是一个权限问题。

It's easy to fix , open your terminal (Applications > Utilities > Terminal) 易于修复 ,打开终端(应用程序>实用程序>终端)

sudo chown -R $USER /usr/local/lib/node_modules

** I strongly recommend you to not use the package management with sudo (sudo npm -g install something), because you can get some issues later ** **我强烈建议您不要将软件包管理与sudo一起使用(sudo npm -g安装一些东西),因为以后您可能会遇到一些问题**

Reference: http://foohack.com/2010/08/intro-to-npm/ 参考: http//foohack.com/2010/08/intro-to-npm/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值