节点版本不会使用n更新 [英] Node version will not update using n

查看:64
本文介绍了节点版本不会使用n更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了提供一些背景信息,我使用这篇中型帖子不要将 sudo npm …仍然一起使用.

To give some context, I set up my machine using this Medium post, Don’t Use sudo with npm …still.

大约一年半以前,我使用 brew 安装了Node,该节点安装了v12.18.1.当时我还使用
brew 安装了 n ,但是直到现在为止都不需要更改版本.

I installed Node using brew about a year and a half ago, which installed v12.18.1. I also installed n at the time using brew, but never had to change versions until now.

我的 .zshrc 文件包括以下内容:

My .zshrc file includes the following:

# 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"

当我使用 n 安装Node v14时,会发生以下情况:

When I install Node v14 with n, the following occurs:

➜  ~ 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.

任何帮助将不胜感激!预先谢谢您.

其他信息: 最初安装Node时,尽管顶部链接的文章指出应该安装 yarn ,但我仍然无法使用 yarn n 使用 brew .为了进行故障排除,我运行了 brewuninstalln ,但是输出了以下内容:

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. To troubleshoot, I ran brew uninstall n, however, the following was 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

然后运行 rm -rf/usr/local/etc/bash_completion.d .之后什么也没打印到终端上.

And so then I ran rm -rf /usr/local/etc/bash_completion.d. Nothing printed to the terminal after.

推荐答案

问题是您将 node 安装到两个位置,而由 n 安装的一个位置是最后在 PATH 变量中.

The problem is you have node installed to two locations, and the one being installed by n is last in the PATH variable.

出于兴趣,您可以运行 n医生,它应该可以解决此问题.

For interest, you can run n doctor and it should pick up this problem.

您可以卸载已安装到/usr/local/bin/node 的节点的副本,也可以重新排列 PATH .代替:

You could either uninstall the copy of node installed to /usr/local/bin/node, or rearrange your PATH. Instead of:

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

尝试:

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

这篇关于节点版本不会使用n更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆