简体   繁体   English

为什么我不能在OSX 10.8.4上安装nodemon或supervisor?

[英]Why can't i npm install nodemon or supervisor on OSX 10.8.4?

I'm just trying to install nodemon or supervisor using terminal, and I keep getting this error which I don't understand. 我只是尝试使用终端安装nodemon或supervisor,我不断收到这个我不明白的错误。 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. 我尝试以管理员的身份运行sudo npm install supervisor -g似乎工作,但是当我删除/添加一些js代码时没有。 Any ideas? 有任何想法吗?

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$ 

PS I'm running this on a pre-existing template and my dependencies are PS我在预先存在的模板上运行它,我的依赖项是

  "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并单击“保存”,但除非我在终端内重新启动服务器,否则效果不会发生。

Late to the party, but it is important to note that you should avoid using sudo when npm installing. 晚会,但重要的是要注意你应该避免在安装npm时使用sudo It is a huge security risk to sudo npm install as you are giving arbitrary scripts root access to your machine. 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

and then 然后

sudo chown -R $USER ~/.npm

Now you should be able to run the commands without sudo: 现在你应该能够在没有sudo的情况下运行命令:

npm install supervisor -g --save

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 . 使用sudo运行与超级用户相同的命令。 The package will be installed in /usr/local/lib/node_modules . 该软件包将安装在/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. 更改npm的设置,将所有全局包安装到您的用户拥有的私人文件夹之一。 See this relevant answer that explains step-by-step the process. 请参阅此相关答案 ,逐步说明该过程。

I know I'm late to the question, but you should check out nvm (node's answer to rbenv or virtualenv ). 我知道我迟到了,但是你应该查看nvm (节点对rbenvvirtualenv的回答)。

Install : 安装

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash

Then add . ~/.nvm/nvm.sh 然后添加. ~/.nvm/nvm.sh . ~/.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 use 0.12.7

Install your libs, EACCESS error-free, and go to town. 安装你的libs,EACCESS没有错误,然后去镇上。 npm install -g supervisor works just fine! 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM