node.js 使用 NVM 时找不到 NPM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33874049/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:34:50  来源:igfitidea点击:

NPM not found when using NVM

node.jsnpmnvm

提问by Rapha?l

I have installed node/npm using the nvm documentation.

我已经使用 nvm 文档安装了 node/npm。

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash

Then:

然后:

nvm install node

At this point node is working but the npm command result with:

此时节点正在工作,但 npm 命令结果为:

npm: command not found

How can I have npm to work correctly ?

我怎样才能让 npm 正常工作?

回答by Rapha?l

I found out that this was a conflict with a previous versions of npm that have not been removed properly despite a apt-get remove node.

我发现这与之前版本的 npm 存在冲突,尽管apt-get remove node.

I solved it by reinstalling npm from scratch:

我通过从头开始重新安装 npm 解决了这个问题:

rm -R ~/.npm ~/.nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
nvm install node

I found the solution here.

我在这里找到了解决方案。

回答by Saeid Alidadi

I fixed this by doing this command:

我通过执行以下命令解决了这个问题:

$ command -v npm

$ command -v npm

and then reopen the shell window.

然后重新打开外壳窗口。

回答by Vaibhav Jain

This problem especially happens in windows which happens because of missing admin rights for cmd.

这个问题尤其发生在 windows 中,这是因为缺少 cmd 的管理员权限。

If you are using Git bash

如果您使用的是 Git bash

  1. Go in installation directory e.g C:\Program Files\Git
  2. Right click properties -> compatibility.
  3. Tick the checkbox with label -> Run as administrator.
  4. Run the git bash again & execute npm list and then npm use 'version_to_be_used'
  1. 进入安装目录,例如 C:\Program Files\Git
  2. 右键单击属性-> 兼容性。
  3. 勾选带有标签的复选框 -> 以管理员身份运行。
  4. 再次运行 git bash 并执行 npm list 然后 npm use 'version_to_be_used'

Same goes for Cmd

Cmd 也一样

回答by Raining

If you run NVM-Windows, don't forget to run nvm on. (this solve the problem as title for me.)

如果您运行 NVM-Windows,请不要忘记运行nvm on. (这为我解决了标题问题。)

回答by Victor Jatobá

Install node using node source distribution:

使用节点源分发安装节点:

curl -sL https://deb.nodesource.com/setup_[version].x | bash -
apt-get install -y nodejs

[version] = the wanted version. See the repository to choose the correct: NodeSource Node.js Binary Distributions

[版本] = 想要的版本。查看存储库以选择正确的:NodeSource Node.js Binary Distributions