为什么 "n" 不在 Mac 上降级我的节点版本?
Why doesn't "n" downgrade my node version on a Mac?
我正在使用 Mac 大苏尔。我想降级 Node.js 的版本。我尝试了下面的方法(没有 sudo 的安装会给我权限错误)…
$ sudo n 14.15.1
installed : v14.15.1 to /usr/local/bin/node
active : v14.17.6 at /usr/local/opt/node@14/bin/node
但我检查时仍然得到当前版本
$ node -v
v14.17.6
顺便说一句,这是我看到的“哪个节点”
$ which node
/usr/local/opt/node@14/bin/node
编辑: 我的 $PATH 当我 运行 'echo $PATH' ...
/usr/local/opt/node@14/bin:/Users/davea/.rvm/gems/ruby-2.7.1/bin:/Users/davea/.rvm/gems/ruby-2.7.1@global/bin:/Users/davea/.rvm/rubies/ruby-2.7.1/bin:/usr/local/opt/node@14/bin:/Users/davea/.nvm/versions/node/v14.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin
编辑 2: 普通用户和 sudo 用户的 PATH 变量 ...
$ env | grep PATH
PATH=/Users/davea/.rvm/gems/ruby-2.7.1/bin:/Users/davea/.rvm/gems/ruby-2.7.1@global/bin:/Users/davea/.rvm/rubies/ruby-2.7.1/bin:/Users/davea/.nvm/versions/node/v14.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin
$ sudo env | grep PATH
PATH=/Users/davea/.rvm/gems/ruby-2.7.1/bin:/Users/davea/.rvm/gems/ruby-2.7.1@global/bin:/Users/davea/.rvm/rubies/ruby-2.7.1/bin:/Users/davea/.nvm/versions/node/v14.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin
n
消息告诉您它刚刚“安装”的版本和“活动”的版本不同。您安装了两个版本的节点,活动版本是 PATH
.
中的第一个版本
活动版本是/usr/local/opt/node@14/bin/node
。我不认识那条路径,不确定用来安装它的是什么。它必须在您的 PATH
变量中并且您的登录脚本中可能有关于将 /usr/local/opt/node@14/bin
添加到 PATH
?
的线索
要让 n
安装的节点版本成为活动版本,您可以删除节点的另一个副本,或者将 /usr/local/bin
放在 PATH
前面以便找到它首先,或最简单的从您的 PATH 变量中删除 /usr/local/opt/node@14/bin
。
如果您要使用多个节点版本,例如 nvm
:
nvm install <version>
更改版本:
nvm use <version>
文档:
我正在使用 Mac 大苏尔。我想降级 Node.js 的版本。我尝试了下面的方法(没有 sudo 的安装会给我权限错误)…
$ sudo n 14.15.1
installed : v14.15.1 to /usr/local/bin/node
active : v14.17.6 at /usr/local/opt/node@14/bin/node
但我检查时仍然得到当前版本
$ node -v
v14.17.6
顺便说一句,这是我看到的“哪个节点”
$ which node
/usr/local/opt/node@14/bin/node
编辑: 我的 $PATH 当我 运行 'echo $PATH' ...
/usr/local/opt/node@14/bin:/Users/davea/.rvm/gems/ruby-2.7.1/bin:/Users/davea/.rvm/gems/ruby-2.7.1@global/bin:/Users/davea/.rvm/rubies/ruby-2.7.1/bin:/usr/local/opt/node@14/bin:/Users/davea/.nvm/versions/node/v14.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin
编辑 2: 普通用户和 sudo 用户的 PATH 变量 ...
$ env | grep PATH
PATH=/Users/davea/.rvm/gems/ruby-2.7.1/bin:/Users/davea/.rvm/gems/ruby-2.7.1@global/bin:/Users/davea/.rvm/rubies/ruby-2.7.1/bin:/Users/davea/.nvm/versions/node/v14.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin
$ sudo env | grep PATH
PATH=/Users/davea/.rvm/gems/ruby-2.7.1/bin:/Users/davea/.rvm/gems/ruby-2.7.1@global/bin:/Users/davea/.rvm/rubies/ruby-2.7.1/bin:/Users/davea/.nvm/versions/node/v14.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.cabal/bin:/Users/davea/.ghcup/bin:/Users/davea/.rvm/bin
n
消息告诉您它刚刚“安装”的版本和“活动”的版本不同。您安装了两个版本的节点,活动版本是 PATH
.
活动版本是/usr/local/opt/node@14/bin/node
。我不认识那条路径,不确定用来安装它的是什么。它必须在您的 PATH
变量中并且您的登录脚本中可能有关于将 /usr/local/opt/node@14/bin
添加到 PATH
?
要让 n
安装的节点版本成为活动版本,您可以删除节点的另一个副本,或者将 /usr/local/bin
放在 PATH
前面以便找到它首先,或最简单的从您的 PATH 变量中删除 /usr/local/opt/node@14/bin
。
如果您要使用多个节点版本,例如 nvm
:
nvm install <version>
更改版本:
nvm use <version>
文档: