avatar

目錄
利用 nvm 在 mac 快速在多個 Node 版本之間切換

nvm (Node Version Manager)

nvm allows you to quickly install and use different versions of node via the command line.
https://github.com/nvm-sh/nvm


Install nvm

zsh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

一開始我安裝失敗,出現了跟這個一樣的狀況 HEAD detached at FETCH_HEAD #2486,最後跟 bestiptx99 說的方法成功了!只要按 q 鍵就可以了:「Just type in q and you’ll be able to come out of this non-interactable page and the rest of the installation gets done.」


Install node.js

Install the latest version of node.js

zsh
nvm install node # "node" is an alias for the latest version

Install a particular version of node.js

zsh
nvm install 12.18.0

Set the default node version

Set the latest version as default

zsh
nvm alias default stable

Set a specific version as default

zsh
nvm alias default 12

Quickly select node versioin

List out all the installed node version

zsh
nvm ls

Select your desired node version

zsh
nvm use 12
zsh
nvm use default

switch between multiple node.js version


Uninstall nvm

不過裝了 nvm 後 generate hexo 超級慢,最後都是把 nvm 卸載了。

zsh
nvm unload

Alternative

唯有繼續用這個方法來在多個 Node 版本之間切換吧

zsh
brew search node
brew unlink node
brew link --force --overwrite node@12
export PATH="/opt/homebrew/opt/node@12/bin:$PATH" >> ~/.zshrc

2023.06.08 updated: 以上 brew unlink link 方法也失效,用以下方法取代。

Alternative 2

方法來自: Hexo Deploy 失敗!? | mycTW Note - Software Management & Development

zsh
nvm use 12
node -v
hexo g -d

Reference


如果您喜歡我的文章,歡迎幫我在下面按5下讚!感謝您的鼓勵和支持!

文章作者: ouoholly
文章鏈接: https://ouoholly.github.io/post/switch-node-version-mac/
版權聲明: 本博客所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。歡迎「部份引用」與介紹(如要全文轉貼請先留言詢問),轉載引用請註明來源 ouoholly 的倉庫,謝謝!

評論