简而言之...
首先,为什么npm http://npmjs.org/建议它只能以非 root 身份运行?我非常不相信其他所有包管理器(apt
, yum
, gem
, pacman
) 要求 sudo 是错误的。
其次,当我遵循他们的建议(并运行npm install
作为非 root),它不会工作(因为非 root 没有 /usr/local/lib 的权限)。我该如何遵循他们的建议?我不会chown -R $USER /usr/local/lib
,因为这对我来说似乎是一个非常糟糕的主意。
详细描述...
我安装了npm http://npmjs.org/ via curl http://npmjs.org/install.sh | sudo sh
(自述文件中的说明)。
当我跑步时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!
但当我跑步时npm install mongoose
没有 sudo 我得到以下信息:
npm info it worked if it ends with ok
npm info using [email protected] /cdn-cgi/l/email-protection
npm info using [email protected] /cdn-cgi/l/email-protection
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 [email protected] /cdn-cgi/l/email-protection
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,然后如果我遵循他们的建议就不起作用。
这引出了我上面最初的问题。