简而言之...
首先,为什么npm建议它只能以非 root 身份运行?我非常不相信所有其他包管理器(apt
, yum
, gem
, pacman
)都要求 sudo 是错误的。
其次,当我按照他们的建议(并npm install
以非 root 用户身份运行)时,它不会起作用(因为非 root 用户没有 /usr/local/lib 的权限)。我该如何听从他们的建议?我不会chown -R $USER /usr/local/lib
,因为这对我来说似乎是一个非常糟糕的主意。
详细描述...
我通过(他们的自述文件中的说明)安装了npm 。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 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,然后如果我按照他们的建议就不起作用。
这导致了我上面最初的问题。