简体   繁体   English

节点版本不会使用 n 更新

[英]Node version will not update using n

To give some context, I set up my machine using this Medium post, Don't Use sudo with npm …still .为了提供一些背景信息,我使用这篇 Medium 帖子设置了我的机器, Don't Use sudo with npm …still

I installed Node using brew about a year and a half ago, which installed v12.18.1.大约一年半前,我使用brew安装了 Node,它安装了 v12.18.1。 I also installed n at the time using brew , but never had to change versions until now.我当时也使用brew安装了n ,但直到现在才需要更改版本。

My .zshrc file includes the following:我的.zshrc文件包括以下内容:

# For globally installed npm packages (without using sudo)
export PATH="$HOME/.npm/bin:$PATH"

# Path to n (managing node versions)
export N_PREFIX="$HOME/.n"
export PATH="$PATH:$N_PREFIX/bin"

When I install Node v14 with n , the following occurs:当我使用n安装 Node v14 时,会发生以下情况:

➜  ~ node -v
v12.18.1
➜  ~ n 14
   installed : v14.15.4 to /Users/myusername/.n/bin/node
      active : v12.18.1 at /usr/local/bin/node
➜  ~ node -v
v12.18.1

I see that the version was successfully installed;我看到版本安装成功; however, the active version doesn't update.但是,活动版本不会更新。 I noticed that the path of the installed version is clearly different than the active version (reference terminal output above), which I suspect is the issue.我注意到安装版本的路径明显不同于活动版本(参考上面的 output 终端),我怀疑这是问题所在。

Any help would be greatly appreciated.任何帮助将不胜感激。 Thank you in advance.先感谢您。


Additional information: When I installed Node initially, yarn was not available despite the article linked at top stating it should be so I installed n using brew .附加信息:当我最初安装 Node 时, yarn不可用,尽管顶部链接的文章说明它应该是可用的,所以我使用n安装了brew To troubleshoot, I ran brew uninstall n , however, the following was output:为了排除故障,我运行了brew uninstall n ,但是,以下是 output:

Warning: The following may be n configuration files and have not been removed!
If desired, remove them manually with `rm -rf`:
  /usr/local/etc/bash_completion.d

And so then I ran rm -rf /usr/local/etc/bash_completion.d .然后我跑了rm -rf /usr/local/etc/bash_completion.d Nothing printed to the terminal after.之后没有打印到终端。

The problem is you have node installed to two locations, and the one being installed by n is last in the PATH variable.问题是您将node安装到两个位置,而n安装的一个在PATH变量中是最后一个。

For interest, you can run n doctor and it should pick up this problem.出于兴趣,您可以运行n doctor ,它应该会解决这个问题。

You could either uninstall the copy of node installed to /usr/local/bin/node , or rearrange your PATH .您可以卸载安装到/usr/local/bin/node的节点副本,或者重新排列PATH Instead of:代替:

export PATH="$PATH:$N_PREFIX/bin"

try:尝试:

export PATH="$N_PREFIX/bin:$PATH"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM