a site to share moments and soughts~

Victor's blog


  • Home
  • Archive
  • Tags
  • about
  •   

© 2025 Victor

Theme Typography by Makito

Proudly published with Hexo

Mac 安装Node.js 20 后`node -v` 和 `npm -v`找不到的解决方案

Posted at 2024-09-21 操作 

Mac 安装Node.js 20 后node -v 和 npm -v找不到的解决方案

根据你提供的信息,我们可以看到 Node.js 20 确实已经成功安装在你的系统上。问题在于它是以 “keg-only” 的方式安装的,这意味着它没有被自动链接到你的系统路径中。让我们按照 Homebrew 的建议来解决这个问题:

  1. 首先,让我们将 Node.js 20 添加到你的 PATH 中。在终端中运行以下命令:

    1
    echo 'export PATH="/opt/homebrew/opt/node@20/bin:$PATH"' >> ~/.zshrc

    这会将必要的路径添加到你的 zsh 配置文件中。

  2. 然后,重新加载你的 zsh 配置文件:

    1
    source ~/.zshrc
  3. 现在,尝试再次运行 node -v 和 npm -v。它们应该能正常工作了。

如果你在未来需要编译依赖 Node.js 的软件,你可能还需要设置以下环境变量。你可以将这些也添加到你的 ~/.zshrc 文件中:

1
2
echo 'export LDFLAGS="-L/opt/homebrew/opt/node@20/lib"' >> ~/.zshrc
echo 'export CPPFLAGS="-I/opt/homebrew/opt/node@20/include"' >> ~/.zshrc

然后再次运行 source ~/.zshrc 来使这些更改生效。

如果在执行这些步骤后仍然遇到问题,你可以尝试强制链接 Node.js:

1
brew link --force node@20

这应该能解决你的问题。如果还有任何疑问或者这些步骤不起作用,请告诉我,我会很乐意继续帮助你。

E=mc2E=mc^2 E=mc2

classDiagram
Class01 <|-- AveryLongClass : Cool
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 --> C2 : Where am i?
Class09 --* C3
Class09 --|> Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label

Share 

 Previous post: Hello World Next post: 关于LaTeX尾注 

© 2025 Victor

Theme Typography by Makito

Proudly published with Hexo