如何brew安装特定版本的Node?

waxmsbnn  于 2023-03-29  发布在  Node.js
关注(0)|答案(4)|浏览(372)

例如,我想安装7.9或7.10,但由于webpack node-sass破坏bug,我想避免安装Node 8。
当我运行brew search node时,我看到的是:
brew search node leafnode llnode node ✔ node-build〉node@0.10 node@0.12 node@4 node@6 nodebrew nodeenv nodeenv caskroom/cask/node-profiler
如果你是指“节点”:它已从caskroom/cask迁移到homebrew/core。您可以通过运行以下命令再次访问它:自制/核心
存在选中的节点(我的当前版本是v7.4.0,然后是node@0.10node@0.12node@4node@6
我不能完全升级到8的原因是node-sass在webpack中不起作用。

刚安装NVM,就收到了这个疯狂的错误日志:

=> nvm source string already in /Users/leongaban/.zshrc => Appending bash_completion source string to /Users/leongaban/.zshrc npm ERR! missing: is-path-cwd@^1.0.0, required by del@3.0.0 npm ERR! missing: is-path-in-cwd@^1.0.0, required by del@3.0.0 npm ERR! missing: p-map@^1.1.1, required by del@3.0.0 npm ERR! missing: pify@^3.0.0, required by del@3.0.0 npm ERR! missing: rimraf@^2.2.8, required by del@3.0.0 npm ERR! missing: bluebird@^3.1.1, required by gulp-html-replace@1.6.2 npm ERR! missing: clone@^1.0.2, required by gulp-html-replace@1.6.2
...

=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:

如果我没阅读,这是否意味着我不能再使用npm来全局安装软件包,而必须使用nvm

更新

我将导出行添加到我的**.zshrc**bash(我不使用bash_profile)

❯ nvm --version
0.33.2
bfhwhh0e

bfhwhh0e1#

在决定使用不同版本的Node时有两种方法。* 第二种方法 * 在我看来更方便和实用(也可能更快)。

* 第一种方式:*

使用以下命令安装其他Node版本(例如14):
| brew install|brew unlink|brew link|
| --------------|--------------|--------------|
| brew安装- github|brew unlink - github|brew链接- github|

brew install node@14
brew unlink node
brew link node@14
node -v

PS您可以使用brew link--overwrite标志,例如:

brew link --overwrite node@14

PS2为什么又是unlink,然后又是link

  • 文件:*

从Homebrew的前缀中删除公式的符号链接。这对于临时禁用公式很有用:
brew unlink formula && commands && brew link formula

  • 换句话说:*

如果您同时安装了node和node@14,其中node是其他版本(...,15或16),那么,对于设置活动版本14:
| 你必须unlink节点|然后link到新安装的版本14|
| --------------|--------------|
| brew unlink node|x1米11米1x|

* 第二种方式:*

安装节点版本管理器(nvm)并选择节点版本:
nvm - githubnvm - home brew

brew install nvm

mkdir ~/.nvm

export NVM_DIR="$HOME/.nvm"
    [ -s "$(brew --prefix)/opt/nvm/nvm.sh" ] && . "$(brew --prefix)/opt/nvm/nvm.sh" # This loads nvm
    [ -s "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" ] && . "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion

nvm install 14

nvm use 14

nvm list
cgfeq70w

cgfeq70w2#

如果正确定义了homebrew/code上的版本,则还必须能够使用brew install node@0.12
您还可以安装多个版本,并使用brew switch命令选择要使用的版本。

无论如何,我推荐使用nvm,它可以通过Homebrew安装。虽然,brew上的版本有缺陷,他们不打算修复它。

8yoxcaq7

8yoxcaq73#

安装最新版本的node并取消链接以前安装的

brew install node@14
brew unlink node
brew link --overwrite node@14
echo 'export PATH="/usr/local/opt/node@14/bin:$PATH"' >> ~/.bash_profile
node -v
i86rm4rw

i86rm4rw4#

brew install --build-from-source node@14

只需使用--build-from-source标志

相关问题