NodeJS “.nvm”不在路径中- Apple M1 MacBook

nwo49xxi  于 2022-11-03  发布在  Node.js
关注(0)|答案(3)|浏览(183)

我使用的是Apple M1 Macbook Pro,带有“zsh”终端,使用“nvm install node”命令安装Node时出现问题。在尝试了该nvm命令后,我直接从https://nodejs.org/en/download/下载了Node
我想确保节点安装通过PATH引用NVM安装节点目录。但是,这是我看到的。
当我运行命令“which node”时,我得到了下面的当前输出。我也列出了预期的输出。有没有办法修复这个问题?

Current output: /usr/local/bin/node
Expected output: /Users/username/.nvm/versions/node/v14.15.4/bin/node
qfe3c7zg

qfe3c7zg1#

如果你仔细看看nvm的安装说明,你会注意到有一个关于如何设置更深的shell集成的信息。
甚至在brew中注意到

$ brew info nvm
...
==> Caveats
Please note that upstream has asked us to make explicit managing
nvm via Homebrew is unsupported by them and you should check any
problems against the standard nvm install method prior to reporting.

You should create NVM's working directory if it doesn't exist:

  mkdir ~/.nvm

Add the following to /Users/geek/.bash_profile or your desired shell
configuration file:

  export NVM_DIR="$HOME/.nvm"
  [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

You can set $NVM_DIR to any location, but leaving it unchanged from
/usr/local/opt/nvm will destroy any nvm-installed Node installations
upon upgrade/reinstall.

Type `nvm help` for further information.

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

既然您对zsh更深层的shell集成感兴趣,那么就这样做吧(我有意不包括官方文档中的片段,这样它就会是最新的)

cygmwpex

cygmwpex2#

1.打开终端并运行
git克隆https://github.com/nvm-sh/nvm.git ~/.nvm
1.运行
源代码nvm.sh

8yoxcaq7

8yoxcaq73#

它在nvm Github readme中提到过。
TLDR
将下面的代码复制到.zshrc文件中:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

相关问题