Homebrew安装Node.js:命令未找到。

7

我有一台运行着 macOS 10.13.1 的 Mac。在成功安装了 Homebrew 后,我尝试使用它来安装 Node.js

brew install node

安装过程在终端中似乎已经完成了,但是进行版本检查时遇到了问题;
node -v

导致
-bash: node: command not found

有什么指导可以修复这个问题吗?我想避免使用二进制安装node。

请安装npm,您可以使用以下命令在终端中进行安装:brew install npm如果您在安装后仍然无法找到npm命令,请确保将npm添加到您的PATH环境变量中。 - Max Baldwin
2
我建议避免使用类似brew或apt-get的工具来安装Node,而是使用N或NVM,https://github.com/creationix/nvm。你可以使用多个版本的Node,并且它们非常容易切换! - ishaan
听起来可能是路径问题。当您键入“which node”时,会得到什么结果? - Natsfan
3个回答

5

我遇到了这个问题,但是因为我安装的是旧版本的 Node,所以出现了这个问题。对于旧版本而言,路径不会被自动修改,以避免与可能安装的最新版本发生冲突。运行 brew install 命令后,如果你想添加它到你的路径中,它应该会给出相关指示。


5

尝试运行此命令

brew link node

一个好的答案总是会包括解释为什么这样做可以解决问题,这样原帖作者和未来的读者都可以从中学习。 - Tyler2P
4
我使用了brew link --overwrite node@16,这对我起作用了。 - Amir Rezvani

0

brew doctor 应该会给你一些提示。

我刚刚为我的 Apple M1 进行了全新的安装,似乎没有任何额外的设置就可以正常工作。

$ brew install node
==> Downloading https://ghcr.io/v2/homebrew/core/c-ares/manifests/1.18.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/c-ares/blobs/sha256:7b1eacc9efbe8ac32a4a
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:7b1e
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libuv/manifests/1.42.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libuv/blobs/sha256:7b0a2b27ac3b806ff9e59
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:7b0a
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/node/manifests/17.2.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/node/blobs/sha256:f3efe9900c885d5bcc3a39
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:f3ef
######################################################################## 100.0%
==> Installing dependencies for node: c-ares and libuv
==> Installing node dependency: c-ares
==> Pouring c-ares--1.18.1.arm64_monterey.bottle.tar.gz
  /opt/homebrew/Cellar/c-ares/1.18.1: 87 files, 665.3KB
==> Installing node dependency: libuv
==> Pouring libuv--1.42.0.arm64_monterey.bottle.tar.gz
  /opt/homebrew/Cellar/libuv/1.42.0: 49 files, 3.5MB
==> Installing node
==> Pouring node--17.2.0.arm64_monterey.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /opt/homebrew/etc/bash_completion.d
==> Summary
  /opt/homebrew/Cellar/node/17.2.0: 2,018 files, 44.4MB
==> Running `brew cleanup node`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> node
Bash completion has been installed to:
  /opt/homebrew/etc/bash_completion.d

$ ls -al /opt/homebrew/bin/node
lrwxr-xr-x  1 ruichen  admin  30 Dec 13 15:56 /opt/homebrew/bin/node -> ../Cellar/node/17.2.0/bin/node

$ node --version
v17.2.0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接