运行npm安装-g yo命令提供-> ERR。

时间:2023-01-18 00:12:27

I just tried to do a npm install but get this error.

我只是试着做一个npm安装,但是得到这个错误。

npm install -g yo
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/yo'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/yo']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/yo',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/yo',
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 12.5.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "yo"
npm ERR! cwd /Users/hemanth
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! path /usr/local/lib/node_modules/yo
npm ERR! fstream_path /usr/local/lib/node_modules/yo
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/yo'
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/hemanth/npm-debug.log
npm ERR! not ok code 0

I changed the permissions of /usr/local with chown, but I'm not sure if this affects my issue. How can i fix it?

我更改了/usr/local和chown的权限,但我不确定这会影响到我的问题。我怎样才能修好它?

3 个解决方案

#1


3  

Edit

Ah, I read your OS wrong, you're on a mac. I'll leave this here though as it might still work (assuming you installed node via Homebrew)

啊,我读错了你的操作系统,你在mac电脑上。我把它留在这里,尽管它可能还在工作(假设你已经安装了通过自制程序的节点)


I've only recently been playing with npm on Linux and this is how I solved it...

我最近才在Linux上玩npm,这是我解决它的方法……

First, set the global npm prefix to a local (to your user) install

首先,将全局npm前缀设置为本地(用户)安装。

mkdir ~/.node && npm config set prefix ~/.node

npm up to and including version 1.4.20 is buggy (it ignores prefix configuration) so first thing we're going to do is install the current npm local to your user.

npm,包括版本1.4.20是错误的(它忽略了前缀配置),所以我们要做的第一件事就是将当前的npm本地安装到您的用户。

npm install -g --prefix=~/.node npm

Now all that's left to do is update your environment variables. In ~/.bashrc or whatever your preference is...

现在剩下要做的就是更新环境变量。在~ /。bashrc或者你喜欢的东西…

if [ -d "$HOME/.node/bin" ]; then
    PATH="$HOME/.node/bin:$PATH"
fi

export NODE_PATH="$NODE_PATH:$HOME/.node/lib/node_modules"

Then source it and you're good to go

然后找到它,你就可以走了。

source ~/.bashrc

#2


0  

See this link as to the reason the following command should work for you

请参见下面的链接,说明以下命令应该为您工作的原因。

sudo npm install -g yo

#3


-1  

try with

试着用

sudo mkdir -p /usr/local/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules
npm install -g yo

#1


3  

Edit

Ah, I read your OS wrong, you're on a mac. I'll leave this here though as it might still work (assuming you installed node via Homebrew)

啊,我读错了你的操作系统,你在mac电脑上。我把它留在这里,尽管它可能还在工作(假设你已经安装了通过自制程序的节点)


I've only recently been playing with npm on Linux and this is how I solved it...

我最近才在Linux上玩npm,这是我解决它的方法……

First, set the global npm prefix to a local (to your user) install

首先,将全局npm前缀设置为本地(用户)安装。

mkdir ~/.node && npm config set prefix ~/.node

npm up to and including version 1.4.20 is buggy (it ignores prefix configuration) so first thing we're going to do is install the current npm local to your user.

npm,包括版本1.4.20是错误的(它忽略了前缀配置),所以我们要做的第一件事就是将当前的npm本地安装到您的用户。

npm install -g --prefix=~/.node npm

Now all that's left to do is update your environment variables. In ~/.bashrc or whatever your preference is...

现在剩下要做的就是更新环境变量。在~ /。bashrc或者你喜欢的东西…

if [ -d "$HOME/.node/bin" ]; then
    PATH="$HOME/.node/bin:$PATH"
fi

export NODE_PATH="$NODE_PATH:$HOME/.node/lib/node_modules"

Then source it and you're good to go

然后找到它,你就可以走了。

source ~/.bashrc

#2


0  

See this link as to the reason the following command should work for you

请参见下面的链接,说明以下命令应该为您工作的原因。

sudo npm install -g yo

#3


-1  

try with

试着用

sudo mkdir -p /usr/local/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules
npm install -g yo