简言之
首先,为什么npm建议它只能作为非根运行?我非常不相信其他所有的包管理器(apt
、yum
、gem
、pacman
)要求sudo是错误的.
其次,当我遵循他们的建议(并以非root用户的身份运行npm install
)时,它将不起作用(因为非root用户无权访问/usr/local/lib).我如何听从他们的建议?我不会go chown -R $USER /usr/local/lib
,因为这对我来说是个很糟糕的主意.
完整描述...
我通过curl http://npmjs.org/install.sh | sudo sh
安装了npm(他们自述中的说明).
当我运行sudo npm install mongoose
时,npm告诉我不要以root用户身份运行它:
npm ERR! sudon't!
npm ERR! sudon't! Running npm as root is not recommended!
npm ERR! sudon't! Seriously, don't do this!
npm ERR! sudon't!
但当我在没有sudo的情况下跑npm install mongoose
时,我得到了以下结果:
npm info it worked if it ends with ok
npm info using npm@0.2.17
npm info using node@v0.4.0-pre
npm info fetch http://registry.npmjs.org/mongoose/-/mongoose-1.0.7.tgz
npm info calculating sha1 /tmp/npm-1297199132405/1297199132406-0.7044695958029479/tmp.tgz
npm info shasum b3573930a22066fbf3ab745a79329d5eae75b8ae
npm ERR! Could not create /usr/local/lib/node/.npm/.cache/mongoose/1.0.7/package.tgz
npm ERR! Failed creating the tarball.
npm ERR! This is very rare. Perhaps the 'gzip' or 'tar' configs
npm ERR! are set improperly?
npm ERR!
npm ERR! couldn't pack /tmp/npm-1297199132405/1297199132406-0.7044695958029479/contents/package to /usr/local/lib/node/.npm/.cache/mongoose/1.0.7/package.tgz
npm ERR! Error installing mongoose@1.0.7
npm ERR! Error: EACCES, Permission denied '/usr/local/lib/node/.npm/.cache/mongoose'
npm ERR! There appear to be some permission problems
npm ERR! See the section on 'Permission Errors' at
npm ERR! http://github.com/isaacs/npm#readme
npm ERR! This will get better in the future, I promise.
npm not ok
所以它告诉我,我不应该使用sudo,如果我听从他们的建议,那就行不通了.
这就引出了我上面最初的问题.