node.js npm 不会安装 express?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12231846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm will not install express?
提问by Devin
I currently have node.js version 0.8.8, and npm 1.1.59 installed.
我目前安装了 node.js 版本 0.8.8 和 npm 1.1.59。
Whenever I run:
每当我运行:
$ npm install -g express
I get this in return:
我得到这个回报:
npm ERR! Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock'
npm ERR! { [Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/devinandrews/.npm/64a534c1-express.lock' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.1.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /Users/devinandrews
npm ERR! node -v v0.8.8
npm ERR! npm -v 1.1.59
npm ERR! path /Users/devinandrews/.npm/64a534c1-express.lock
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/devinandrews/npm-debug.log
npm ERR! not ok code 0
I'm pulling my hair out right now trying to figure this out.
我现在正在拔头发试图弄清楚这一点。
Update:
更新:
I ran
我跑了
$ npm -g ls
to see my what npm has installed globally:
查看我的 npm 在全球安装了什么:
/usr/local/lib
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
but if i run:
但如果我跑:
$ npm ls
it returns empty?
它返回空?
回答by ty.
I had the same problem, and npm cache cleardid not fix it. This problem is caused because the .npmdirectory in your home directory was created with root privileges. Most likely the first npm command you ran was sudo npm -gand now you are trying to npm installin a local directory.
我有同样的问题,并npm cache clear没有解决它。出现此问题是因为.npm您的主目录中的目录是使用 root 权限创建的。您运行的第一个 npm 命令很可能是sudo npm -g,现在您正尝试npm install在本地目录中执行。
To solve:
要解决:
sudo chown -R yourusername ~/.npm- This may not be necessary but I also had to
rmdir ~/tmp
sudo chown -R yourusername ~/.npm- 这可能没有必要,但我也不得不
rmdir ~/tmp
npm installfrom package.json should work after this.
npm install从 package.json 应该在此之后工作。
回答by supernova
run npm cache cleanand try to install it again
运行npm cache clean并尝试再次安装
回答by user1640025
i got the same problem , This problem is caused because the .npm directory in your home directory was created with root privileges.
我遇到了同样的问题,这个问题是因为你的主目录中的 .npm 目录是用 root 权限创建的。
use :
用 :
$sudo npm install -g express
回答by galo hernandez
The solution is:
解决办法是:
1 - chown to your user the .npm folder :
1 - chown 给你的用户 .npm 文件夹:
sudo chown -R Webmaste /Users/webmaste/.npm/
2 - At your test folder or your folder:
2 - 在您的测试文件夹或您的文件夹中:
sudo npm install -g [email protected]
3 - Invoke express from your actual location:
3 - 从您的实际位置调用 express:
/usr/local/share/npm/bin/express
4 -
4 -
sudo cd . && npm install
5 - finally:
5 - 最后:
node app
the final message in the console should look like this:
控制台中的最终消息应如下所示:
Express server listening on port 3000 in development mode
回答by Mark Karwowski
If you can't see nothing wrong with using sudo npm install -g package_name. And have the problem with typing a password you can always add yourself to sudoers files or to the same group that npmexecutable belongs to.
如果您看不出使用 sudo 有什么问题npm install -g package_name。并且在输入密码时遇到问题,您可以随时将自己添加到 sudoers 文件或npm可执行文件所属的同一组中。
And so to add yourself to sudoers for npm edit /etc/sudoersadding something like this to the bottom of the file:
因此,要将自己添加到 sudoers 以进行 npm 编辑/etc/sudoers,请在文件底部添加如下内容:
your_username localhost=/usr/local/bin/npm
Hereis step by step guide on how to achieve that if you need more details.
如果您需要更多详细信息,这里是有关如何实现这一目标的分步指南。
回答by Doc Honcho
In my case, instead of the ~/.npm directory being owned by root, it was ~/tmp, which I didn't think to check until one of the error messages finally led me to find. Procedure for fixing is pretty easy, since it's a tmp directory, we can just blow it away and start again with one owned by you.
在我的情况下,不是 ~/.npm 目录由 root 拥有,而是 ~/tmp,我没想到要检查它,直到其中一条错误消息最终让我找到。修复过程非常简单,因为它是一个 tmp 目录,我们可以将它吹走,然后从您拥有的一个重新开始。
sudo rmdir ~/tmp
mkdir ~/tmp
回答by Veljko P.
Run powershell as administrator, then type:
以管理员身份运行 powershell,然后输入:
Set-ExecutionPolicy RemoteSigned
then try install again.
然后再次尝试安装。

