bash NPM 不会在 Mac 上安装任何软件包。新的,干净的构建。`EACCES` 和其他错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25258361/
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
NPM won't install any package on Mac. New, clean build. `EACCES` & other errors
提问by 2540625
I've just rebuild my Mavericks (Mac OS X Version 9.4) machine from scratch. I am the administrator and only user of this machine.
我刚刚从头开始重建我的 Mavericks(Mac OS X 9.4 版)机器。我是这台机器的管理员和唯一的用户。
- I installed Git via their
git-2.0.1-intel-universal-snow-leopard.pkg
(http://git-scm.com/downloads) in their default/usr/local/git/bin/git
location. - I installed Node via their
node-v0.10.30.pkg
(http://nodejs.org/download/) in their default/usr/local/bin/node
location. - The final step of Node's installer package included a note that they also installed NPM in their default
/usr/local/bin/npm
location. - My
$PATH
echoes/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
(it contains/usr/local/bin
).
- 我通过他们的
git-2.0.1-intel-universal-snow-leopard.pkg
( http://git-scm.com/downloads) 在他们的默认/usr/local/git/bin/git
位置安装了 Git 。 - 我通过他们的
node-v0.10.30.pkg
( http://nodejs.org/download/) 在他们的默认/usr/local/bin/node
位置安装了 Node 。 - Node 安装程序包的最后一步包括一个注释,即他们还在默认
/usr/local/bin/npm
位置安装了 NPM 。 - 我的
$PATH
回声/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
(它包含/usr/local/bin
)。
Running npm install -g bower
results in:
运行npm install -g bower
结果:
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/bower']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/bower',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/bower',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "bower"
npm ERR! cwd /Users/Home
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR! path /usr/local/lib/node_modules/bower
npm ERR! fstream_path /usr/local/lib/node_modules/bower
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Home/npm-debug.log
npm ERR! not ok code 0
Running similar installations (npm install -g yo
, npm install -g grunt
, npm install -g nvm
, npm install -g npm
) results in what appears to be the same list of errors.
运行类似的安装 ( npm install -g yo
, npm install -g grunt
, npm install -g nvm
, npm install -g npm
) 会导致出现相同的错误列表。
Several people online suggest forcing the installation via sudo
, but several others warn this could cause later issues. The manuals for these packages seem not to mention requirement of sudo
, and in some cases, they have advised contacting NPM when this issue arises.
网上有几个人建议通过 强制安装sudo
,但其他几个人警告说这可能会导致以后的问题。这些包的手册似乎没有提到 的要求sudo
,并且在某些情况下,他们建议在出现此问题时联系 NPM。
Running npm cache clear
does not correct the issue.
运行npm cache clear
并不能解决问题。
Running ls -la
in the home (~
) directory shows my Mac OS X username as the owner of my .npm
directory: drwxr-xr-x 15 admin staff 510 Aug 11 23:53 .npm
ls -la
在 home ( ~
) 目录中运行将我的 Mac OS X 用户名显示为我的.npm
目录的所有者:drwxr-xr-x 15 admin staff 510 Aug 11 23:53 .npm
Does anyone know what has gone wrong and how to correct this? Thank you.
有谁知道出了什么问题以及如何纠正这个问题?谢谢你。
回答by 2540625
By the way, I solved this issue by changing the owner of /usr/local
to be myself, in order to allow NPM to modules in its default location without further requiring sudo
for each package's installation.
顺便说一下,我通过将所有者更改/usr/local
为我自己来解决这个问题,以便允许 NPM 将模块放在其默认位置,而无需进一步sudo
安装每个包。
sudo chown -R `whoami` /usr/local
回答by alandarev
EACCES is an error of not having access on doing an operation.
EACCES 是无法访问进行操作的错误。
Taken the line: npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
we can see that npm
was unable to create a directory in the given location.
采取的行:npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
我们可以看到npm
无法在给定位置创建目录。
The reason is very likely that you are not running the command as super user. In fact, the error log is even suggesting that:
原因很可能是您没有以超级用户身份运行命令。事实上,错误日志甚至暗示:
npm ERR! Please try running this command again as root/Administrator.
npm 错误!请尝试以 root/管理员身份再次运行此命令。
To run as administrator, you have to prefix those commands with sudo
. That is:
要以管理员身份运行,您必须在这些命令前加上sudo
. 那是:
sudo npm install -g bower
. You will be required to type in a password for security reasons.
sudo npm install -g bower
. 出于安全原因,您将需要输入密码。
回答by Scott Stensland
to start fresh remove prior node.js and npm installs as well as these :
重新开始删除之前的 node.js 和 npm 安装以及这些:
~/.npmrc ~/.npm ~/tmp ~/.npm-init.js
~/.npmrc ~/.npm ~/tmp ~/.npm-init.js
to install nodejs and npm as yourself NOT root do these commands (linux) :
以自己的身份安装 nodejs 和 npm,而不是 root 执行这些命令(linux):
mkdir ${HOME}/bin
download source from : http://nodejs.org/download/
下载源:http: //nodejs.org/download/
cd v0.10.30/
./configure --prefix=${HOME}/bin/nodejs
make -j8
make install
which puts it into dir defined by above --prefix
将它放入上面定义的目录中 --prefix
export PATH=${HOME}/bin/nodejs/bin:$PATH
NODE_PATH so node can find dir for modules otherwise npm install xxx will put newly installed module into dir in curr dir :
NODE_PATH 因此节点可以找到模块的目录,否则 npm install xxx 会将新安装的模块放入 curr 目录中的目录:
export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules
do above AND use syntax : npm install xxxxx -g always use the -g for global
执行以上操作并使用语法: npm install xxxxx -g 始终使用 -g 表示全局
nodejs install gives you npm as well :
nodejs install 也给你 npm :
ls -la ${HOME}/bin/nodejs/bin
回答by Golo Roden
I'd recommend that you install Node.js using a version manager such as nvm. This way, you kill two birds with one stone:
我建议你使用版本管理器安装Node.js的诸如NVM。这样,您可以用一块石头杀死两只鸟:
- First, you can manage multiple versions of Node.js on the same machine (which you willwant to do sooner or later).
- Second, you get around all the access problems you experience when installing Node.js without it. At least that's my experience.
- 首先,您可以在同一台机器上管理多个版本的 Node.js(您迟早会想要这样做)。
- 其次,您可以解决在没有 Node.js 的情况下安装 Node.js 时遇到的所有访问问题。至少这是我的经验。
Basically it's as easy as running
基本上就像跑步一样简单
$ curl https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash
from the command line.
从命令行。
回答by Adam ?ipicky
(SOLUTION ANSWER)
(解决方案答案)
Hi Guys,
嗨,大家好,
I had the same problem on my MacBook Pro 2018. After trie installing any dependency globally (with "-g" or "--global") I did receive an issue "EACCES" error (it's about permissions)
我在 MacBook Pro 2018 上遇到了同样的问题。在尝试全局安装任何依赖项(使用“-g”或“--global”)后,我确实收到了一个问题“EACCES”错误(与权限有关)
You could simply add "sudo" before your commandswhat will force it.
您可以简单地在您的命令之前添加“sudo”,以强制执行它。
For example:
例如:
sudo npm install gulp -g
or
或者
sudo npm install browser-sync -g
Enjoy!
享受!
回答by karolus
It's generally not advised to run sudo
unless absolutely necessary.
sudo
除非绝对必要,否则通常不建议运行。
For issues like this, NPMcan solve many issues, and allow multiple node versions to be used, and selected depending upon your use case.
对于这样的问题,NPM可以解决很多问题,并允许使用多个节点版本,并根据您的用例进行选择。
I had a similar issue setting up a new machine, and installing NPM took care of the issue.
我在设置新机器时遇到了类似的问题,安装 NPM 解决了这个问题。