# 2021 nvm for mac ###### tags: `學習` `nvm` ## 查詢自己電腦 ``` d ``` ## 安裝 NVM ### 先下載 ``` curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash ``` ### 設定環境變數 接著要按照你 terminal shell 是 bash 或是 zsh 在以下 `~/.bash_profile`、`~/.zshrc`、`~/.profile` 或 `~/.bashrc` 其中一個做對應設定。 #### 步驟一 打開文件 ``` nano .bash_profile ``` ![](https://i.imgur.com/TxoDk72.png) #### 步驟二 貼上文件 ``` export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm ``` ![](https://i.imgur.com/bOT76bQ.png) #### 步驟三 `^x` 離開 #### 步驟四 ![](https://i.imgur.com/WMAhTj5.png) #### 步驟五 ![](https://i.imgur.com/4ZNu1Sf.png) 輸入 ``` source ~/.bash_profile ``` ### 重新關掉終端機 ### 檢查是否安裝成功 ``` nvm --version ``` ![](https://i.imgur.com/T3XJrKh.png) ## NVM 指令 ### 目前該 nvm 版號 ``` nvm -v ``` ### 查看此台電腦安裝資訊 ``` nvm ls ``` ### 查看有哪些 Node.js 版號可以安裝 ``` nvm ls-remote ``` ### 安裝指定 Node.js 版號 ``` nvm install ${版本號碼} ``` ### 移除該 Node.js 版號 ``` nvm uninstall ${版本號碼} ``` ### 切換指定 Node.js 版號 ``` nvm use ${版本號碼} ``` ### 設定此台電腦預設的 Node.js 版號 ``` nvm alias default ${版本號碼} ``` ## 參考網址 https://github.com/nvm-sh/nvm#troubleshooting-on-macos https://www.youtube.com/watch?v=wokqRyMfdm4&ab_channel=AyyazTech https://simonallen.coderbridge.io/2020/05/29/nvm-note/ https://github.com/nvm-sh/nvm https://www.youtube.com/watch?v=zCz_HqTgpLI https://www.howtogeek.com/444596/how-to-change-the-default-shell-to-bash-in-macos-catalina/ https://www.youtube.com/watch?v=YJdh2E4idmY&ab_channel=WenXuanDecode%E6%96%87%E8%BD%A9%E8%A7%A3%E7%A0%81