例如,我想安装 7.9 或 7.10,但由于 webpack node-sass
破坏性错误而想避免使用 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 nodenv caskroom/cask/node-profiler
If you meant "node" specifically: It was migrated from caskroom/cask to homebrew/core. You can access it again by running: brew tap homebrew/core
有 Node 被检查(我当前的版本是 v7.4.0
然后 node@0.10
, node@0.12
, node@4
和 node@6
?
我不能完全升级到 8 的原因是 node-sass 不能在 webpack 中工作。
刚刚安装了 NVM,得到了这个疯狂的错误日志:
=> nvm 源字符串已经在/Users/leongaban/.zshrc
=> 将 bash_completion 源字符串附加到/Users/leongaban/.zshrc
npm 错误!缺失:is-path-cwd@^1.0.0,del@3.0.0 需要
npm 错误!缺失:is-path-in-cwd@^1.0.0,del@3.0.0 需要
npm 错误!缺失:p-map@^1.1.1,del@3.0.0 需要
npm 错误!缺失:pify@^3.0.0,del@3.0.0 需要
npm 错误!缺失:rimraf@^2.2.8,del@3.0.0 需要
npm 错误!缺失:bluebird@^3.1.1,gulp-html-replace@1.6.2 需要
npm 错误!缺失:clone@^1.0.2,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
最佳答案
决定使用不同版本的 Node.js 有两种方法。 第二种方式在我看来更方便实用(也可能更快)。
第一种方式:
使用以下方式安装其他 Node 版本(例如 14):
brew install |
brew unlink |
brew 链接 |
---|---|---|
brew install - github | brew unlink - github | brew link - github |
brew install node@14
brew unlink node
brew link node@14
node -v
PS你可以使用带有--overwrite
标志的brew link
,例如:
brew link --overwrite node@14
PS2为什么unlink
然后又link
?
文档:
Remove symlinks for formula from Homebrew's prefix. This can be useful for temporarily disabling a formula:
brew unlink formula && commands && brew link formula
换句话说:
如果您同时安装了 node 和 node@14,其中 node 是其他版本(..,15 或 16),那么,设置事件版本 14:
你必须取消链接 Node |
然后 link 到新安装的版本 14 |
---|---|
brew unlink node |
brew链接 Node @14 |
第二种方式:
安装 Node 版本管理器(nvm)并选择 Node 版本:
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
关于javascript - 如何brew安装特定版本的Node?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44803721/