文、意如
Node.js 的版本管理工具:
NVM (Node Version Manager)
windows環境
1.下載 mvn-setup.zip
https://github.com/coreybutler/nvm-windows/releases





安裝完後開啟 cmd

輸入:nvm version
如果安裝成功即可看到版本號

常用指令
查看有那些node.js版本可以安裝
nvm list available
查看本機安裝哪些 Node.js 版本,及 active(使用) 哪一版
nvm list
安裝指定 Node.js 版本nvm install 版本號
切換到指定 Node.js 版本nvm use 版本號
檢查當前 active 的 node 和 npmnode -v
npm -v


因為我的電腦還在windows 7 所以最新版本的都不支援。

嘗試降版本到12.22.3 才能執行
輸入 node -v
看到版本號代表安裝成功

目前安裝的版本:

有*字號代表 目前所使用的版本為 12.22.3
這個就是使用nvm 管理node.js版本的方便之處,再也不用因版本的問題而困擾。
Mac環境
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
環境變數設定
接著要按照你 terminal shell 是 bash 或是 zsh 在以下 ~/.bash_profile
、~/.zshrc
通常 bash 對應 .bash_profile
或 .bashrc
檔案,zsh 對應 .zshrc
檔案。
兩者擇一
- bash
- zsh
要知道自己是 bash 或 zsh 最簡單方式就是打開 terminal 看看視窗上面寫什麼:

bash
預設的情況下,MacOS 中可能沒有任何一個指令設定檔案,此時可以使用 touch ~/.bash_profile
新增一個文字檔案在根目錄上,
任一層 finder 配合command + 上,可到根目錄 (使用者→電腦名)

再按下Command + Shift+ .
可顯示隱藏的檔案
回到資料根目錄後可以找到 .bash_profile
,

接下來使用任何文字編輯器打開該檔案,並加入以下程式碼存檔即可。
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
zsh
如果沒有此檔案,新增一個
touch ~/.zshrc
可以打開 .zshrc
加入以下片段後重啟(注意:.zshrc
通常在使用者根目錄下並且為隱藏檔,找到後使用任何文字編輯器打開編輯)。
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
設定完成以後,重新開啟終端機 按下 nvm
就會跳出如下圖就算完成了。

nvm ls-remote:列出目前可用的遠端 Node.js 版本
nvm install :安裝特定版本的 Node.js
nvm ls:列出本定端所安裝的 Node.js 環境
nvm alias default node:設定命令列預設開啟的 Node.js 版本
nvm use:當前命令列套用特定版本的 Node.js


Yiru@Studio - 關於我 - 意如