I'm just trying to install nodemon or supervisor using terminal, and I keep getting this error which I don't understand. I tried running as the administrator with sudo npm install supervisor -g
which seemed to work, but than didn't when i deleted/added some js code. Any ideas?
我只是尝试使用终端安装nodemon或supervisor,我不断收到这个我不明白的错误。我试着以管理员的身份运行sudo npm install supervisor -g似乎工作,但是当我删除/添加一些js代码时没有。有任何想法吗?
Squirrels-MacBook-Air:lesson7_examples Squirrel$ npm install nodemon -g
npm http GET https://registry.npmjs.org/nodemon
npm http 304 https://registry.npmjs.org/nodemon
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/nodemon',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/nodemon',
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.4.1
npm ERR! command "node" "/usr/local/bin/npm" "install" "nodemon" "-g"
npm ERR! cwd /Users/Squirrel/Documents/Code/Memry/Memry_Mongoose
npm ERR! node -v v0.10.21
npm ERR! npm -v 1.3.11
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! fstream_path /usr/local/lib/node_modules/nodemon
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/nodemon'
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/Squirrel/Documents/Code/Memry/Memry_Mongoose/npm-debug.log
npm ERR! not ok code 0
Squirrels-MacBook-Air:lesson7_examples Squirrel$
P.S. I'm running this on a pre-existing template and my dependencies are
附:我在预先存在的模板上运行它,我的依赖项是
"dependencies": {
"mongoose": "~3.6.15",
"express": "~3.3.4",
"jade": "~0.34.1",
"email-validator": "~0.1.2"
}
When I tried sudo this is what happened:
当我尝试sudo时,这就是发生的事情:
sudo npm install supervisor -g --save
Password:
npm http GET https://registry.npmjs.org/supervisor
npm http 304 https://registry.npmjs.org/supervisor
/usr/local/bin/node-supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
/usr/local/bin/supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
supervisor@0.5.6 /usr/local/lib/node_modules/supervisor
Which seemed to work. But than in the application code I began to add and delete javascript and click save, yet the effects wouldn't take place unless I restarted the server within terminal.
这似乎有效。但是在应用程序代码中我开始添加和删除javascript并单击“保存”,但除非我在终端内重新启动服务器,否则效果不会发生。
3 个解决方案
#1
6
You're encountering an EACCES
error, which means you don't have the rights to create a directory in /usr/local/lib/node_modules/nodemon
as a standard user in Mac OS X.
您遇到EACCES错误,这意味着您无权在Mac OS X中作为标准用户在/ usr / local / lib / node_modules / nodemon中创建目录。
There are two solutions:
有两种解决方案:
- Run the same command as a superuser, using
sudo
. The package will be installed in/usr/local/lib/node_modules
. - Change npm's settings to install all of your global packages into one of your private folders, that your user has ownership of. See this relevant answer that explains step-by-step the process.
使用sudo运行与超级用户相同的命令。该软件包将安装在/ usr / local / lib / node_modules中。
更改npm的设置,将所有全局包安装到您的用户拥有的私人文件夹中。请参阅此相关答案,逐步说明该过程。
#2
11
Late to the party, but it is important to note that you should avoid using sudo
when npm installing. It is a huge security risk to sudo npm install
as you are giving arbitrary scripts root access to your machine.
晚会,但重要的是要注意你应该避免在安装npm时使用sudo。 sudo npm install存在巨大的安全风险,因为您可以根据机器的任意脚本进行root访问。
Instead you should make yourself the owner of the directories in which the NPM
相反,你应该让自己成为NPM目录的所有者
sudo chown -R $USER /usr/local
sudo chown -R $ USER / usr / local
and then
sudo chown -R $USER ~/.npm
sudo chown -R $ USER~ / .npm
Now you should be able to run the commands without sudo:
现在你应该能够在没有sudo的情况下运行命令:
npm install supervisor -g --save
npm install supervisor -g --save
#3
2
I know I'm late to the question, but you should check out nvm (node's answer to rbenv or virtualenv).
我知道我迟到了,但是你应该查看nvm(节点对rbenv或virtualenv的回答)。
Install:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
curl -o-https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh |庆典
Then add . ~/.nvm/nvm.sh
to your ~/.bashrc
, ~/.profile
, or ~/.zshrc
然后加 。 〜/ .nvm / nvm.sh到〜/ .bashrc,〜/ .profile或〜/ .zshrc
Usage:
If you wanted to use version 0.10, run nvm install 0.12.7
(or nvm install stable
), then nvm use 0.12.7
.
如果要使用版本0.10,请运行nvm install 0.12.7(或nvm install stable),然后nvm使用0.12.7。
Install your libs, EACCESS error-free, and go to town. npm install -g supervisor
works just fine!
安装你的libs,EACCESS没有错误,然后去镇上。 npm install -g supervisor工作得很好!
To load a specific version default in new tabs, use the command
nvm alias default 0.12.7
要在新选项卡中加载特定版本的默认值,请使用命令nvm alias default 0.12.7
#1
6
You're encountering an EACCES
error, which means you don't have the rights to create a directory in /usr/local/lib/node_modules/nodemon
as a standard user in Mac OS X.
您遇到EACCES错误,这意味着您无权在Mac OS X中作为标准用户在/ usr / local / lib / node_modules / nodemon中创建目录。
There are two solutions:
有两种解决方案:
- Run the same command as a superuser, using
sudo
. The package will be installed in/usr/local/lib/node_modules
. - Change npm's settings to install all of your global packages into one of your private folders, that your user has ownership of. See this relevant answer that explains step-by-step the process.
使用sudo运行与超级用户相同的命令。该软件包将安装在/ usr / local / lib / node_modules中。
更改npm的设置,将所有全局包安装到您的用户拥有的私人文件夹中。请参阅此相关答案,逐步说明该过程。
#2
11
Late to the party, but it is important to note that you should avoid using sudo
when npm installing. It is a huge security risk to sudo npm install
as you are giving arbitrary scripts root access to your machine.
晚会,但重要的是要注意你应该避免在安装npm时使用sudo。 sudo npm install存在巨大的安全风险,因为您可以根据机器的任意脚本进行root访问。
Instead you should make yourself the owner of the directories in which the NPM
相反,你应该让自己成为NPM目录的所有者
sudo chown -R $USER /usr/local
sudo chown -R $ USER / usr / local
and then
sudo chown -R $USER ~/.npm
sudo chown -R $ USER~ / .npm
Now you should be able to run the commands without sudo:
现在你应该能够在没有sudo的情况下运行命令:
npm install supervisor -g --save
npm install supervisor -g --save
#3
2
I know I'm late to the question, but you should check out nvm (node's answer to rbenv or virtualenv).
我知道我迟到了,但是你应该查看nvm(节点对rbenv或virtualenv的回答)。
Install:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
curl -o-https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh |庆典
Then add . ~/.nvm/nvm.sh
to your ~/.bashrc
, ~/.profile
, or ~/.zshrc
然后加 。 〜/ .nvm / nvm.sh到〜/ .bashrc,〜/ .profile或〜/ .zshrc
Usage:
If you wanted to use version 0.10, run nvm install 0.12.7
(or nvm install stable
), then nvm use 0.12.7
.
如果要使用版本0.10,请运行nvm install 0.12.7(或nvm install stable),然后nvm使用0.12.7。
Install your libs, EACCESS error-free, and go to town. npm install -g supervisor
works just fine!
安装你的libs,EACCESS没有错误,然后去镇上。 npm install -g supervisor工作得很好!
To load a specific version default in new tabs, use the command
nvm alias default 0.12.7
要在新选项卡中加载特定版本的默认值,请使用命令nvm alias default 0.12.7