未findnpm:命令。 节点已安装时如何重新安装NPM? NPM去了哪里?

我开始学习使用AngularJS教程构build现代Web应用程序,并且很早就遇到了问题。

我有节点安装:

/path/ang-news node -v v0.10.26 

早些时候我在使用NPM,但是和Yeoman一起遇到了麻烦。 我已经重复了这些步骤,但Grunt停止工作,所以我开始新鲜。

我跑了:

 $ sudo npm install -g generator-angular 

和所有的依赖关系正在安装,直到我收到:

 npm WARN package.json mongo@0.1.0 No repository field. npm ERR! peerinvalid The package generator-karma does not satisfy its siblings' peerDependencies requirements! npm ERR! peerinvalid Peer generator-angular@0.9.1 wants generator-karma@>=0.8.2 

然后我尝试更新:

 $ npm update -g 

我应该以pipe理员身份运行它。 我收到了大量的错误信息,这似乎是最相关的:

 npm ERR! Please try running this command again as root/Administrator. npm ERR! System Darwin 13.1.0 npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "update" "-g" npm ERR! cwd /path/ang-news npm ERR! node -v v0.10.26 npm ERR! npm -v 1.4.3 npm ERR! not ok code 0 

然后我试着卸载generator-karma并重新开始:

 $ sudo npm uninstall -g generator-karma 

但收到:

 sudo: npm: command not found $ npm -v -bash: /usr/local/bin/npm: No such file or directory 

我的第一个问题是:为什么NPM突然消失?

[编辑:赞@ @ try-catch-finally来指出在发出命令时在普通用户和sudo之间切换时发生的破坏。 事实certificate,我搞乱了我的用户环境,NPM不再安装。]

我的理解是在安装Node时安装了NPM,所以我的第二个问题是:如何重新安装NPM? 我宁愿不必从一开始就重新安装节点。

[编辑:荣誉@hawk和@ try-catch-finally – 它似乎没有单独安装NPM是一个选项,但有两个简单的方法来重新安装 。

  1. 如果你有一个工作节点,你可以重新安装npm

curl -L https://npmjs.org/install.sh | sudo sh

  1. 不幸的是, npm update -g并没有做任何人所期望的事情。 解决这个问题是在npm路线图上,但是这需要一段时间。

  2. 除非(例如generator-angulargrunt-cli )您想要将该包用作命令,否则几乎不需要全局安装包。

以防万一你用brew做了这个,我推荐这篇文章在github上。 会节省你很多时间。

https://gist.github.com/DanHerbert/9520689

在Mac OS X上为自制程序用户修复npm运行以下命令以删除所有现有的全局npm模块,卸载节点&npm,使用正确的默认值重新安装节点,将npm作为自己的pacakge,并configuration全局npm模块的位置被安装。

 rm -rf /usr/local/lib/node_modules brew uninstall node brew install node --without-npm echo prefix=~/.node >> ~/.npmrc curl -L https://www.npmjs.com/install.sh | sh 

Node和npm应该在这一点上正确安装。 最后一步是将〜/ .node / bin添加到PATH中,以便全局安装的命令可用。 我将这一行添加到我的〜/ .path脚本中,该脚本通过〜/ .bash_profile运行。 按原样运行以下行。

 export PATH="$HOME/.node/bin:$PATH" 

在执行命令后,我遇到了同样的问题,在redhat 7.1上安装了最新版本的npm:

  npm install npm@latest -g 

经过一番尝试,我发现了解决scheme:

  yum reinstall npm 

我希望这可以帮助redhat / centos用户。