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

问题描述

我使用的是带有“zsh”终端的 Apple M1 Macbook pro,使用“nvm install node”命令安装 Node 时出现问题。在尝试了 nvm 命令后,我直接从 https://nodejs.org/en/download/

下载了 Node

我想确保节点安装通过 PATH 引用 NVM 安装节点的目录。然而,这就是我所看到的。

当我运行命令“哪个节点”时,我得到以下当前输出。我也列出了预期的输出。有没有办法解决这个问题?

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

解决方法

如果您仔细查看 nvm 安装说明,您会注意到有关于如何设置 deeper shell integration 的信息。

它甚至在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 集成感兴趣,do this(我故意不包含官方文档中的片段,因此它将是最新的)