# 【nvm】Node.js 管理工具

- #### nvm

[https://github.com/nvm-sh/nvm](https://github.com/nvm-sh/nvm)

[https://github.com/coreybutler/nvm-windows ](https://github.com/coreybutler/nvm-windows)(windows 安裝) 如果安裝前有安裝node.js 請先移除 [【windows 移除 node.js】](https://bookstack.treemanou.com/books/treeman/page/nodejs-windows-nodejs)

[![image-1639308909063.png](https://bookstack.treemanou.com/uploads/images/gallery/2021-12/scaled-1680-/gAALUONYlLhFPyBK-image-1639308909063.png)](https://bookstack.treemanou.com/uploads/images/gallery/2021-12/gAALUONYlLhFPyBK-image-1639308909063.png)

### Mac 安裝nvm

```shell
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
```

如果下nvm指令找不到

在以下檔案(依照你常用的套件擇一)加入以下文字

*bash*: `vim ~/.bashrc`

*zsh*: `vim ~/.zshrc```

```shell
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
```

重新登入或是依使用shell則一重新讀入設定檔

*bash*: `source ~/.bashrc`

*zsh*: `source ~/.zshrc`

參考: [https://github.com/nvm-sh/nvm#installing-and-updating](https://github.com/nvm-sh/nvm#installing-and-updating)

---

### MVN 常用指令

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

```shell
# 列出目前電腦有安裝nodejs版本
nvm list

# 目前網路上可用的nodejs 版本
## mac
nvm ls-remote
## windows
nvm list available

#安裝12.19.0版本
nvm install v12.19.0 

#移除12.19.0版本
nvm nuinstall v12.19.0

#使用12.19.0版本
nvm use 12.19.0

#查看目前版本
nvm -v 
```