Multiple Node Versions in MacOS
Node Version Manager (nvm) is a great tool to use the multiple Node version in a system.
Install Node
brew install nodejs
Check Node Version
node --version
Step - 1
Install NVM
- via curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
- via wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
Add source lines to the profile
~/.bashrc
, ~/.profile
, or ~/.zshrc
file.
This loads nvm
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"
Restart terminal or Open New Terminal
Check NVM Version
nvm --version
Output:
0.39.2
Step - 2
Install Multiple Node.js Versions
- Latest Version
nvm install node
- Specific Version
nvm install 10.15.3
- LTS Version
nvm install --lts
- Set Default Version
nvm alias default 16
Step - 3
List Install Versions
nvm ls
Output:
➜ ~ nvm ls
-> v10.15.3
v16.13.2
system
default -> 10.15.3 (-> v10.15.3)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.13.2) (default)
stable -> 16.13 (-> v16.13.2) (default)
lts/* -> lts/gallium (-> v16.13.2)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.9 (-> N/A)
lts/fermium -> v14.18.3 (-> N/A)
lts/gallium -> v16.13.2
Step - 4
Switch Node Version
nvm use 16
Switch to Default Version
nvm use default
Step - 5
Uninstall Node Version
nvm uninstall 10
Step - 6
Uninstall NVM (Node Version Manager)
nvm unload
Step - 7 (Optional)
Set Node version in the .nvmrc
file in the project’s root for specific projects
echo "16" > .nvmrc
Upgrade to the Latest NVM.
For manual upgrade with git (requires git v1.7.10+):
- change to the $NVM_DIR
- pull down the latest changes
- check out the latest version
- activate the new version
(
cd "$NVM_DIR"
git fetch --tags origin
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
Enjoy the Development!!