To myself... May you install Node.js in a way that's convenient to switch to different versions for either compatibility purposes or new feature experimentation.

Existing Node installed with Brew

If Node.js is installed with Brew, most likely there's also yarn installed (if you're using yarn).

The first step is to uninstall yarn

brew uninstall yarn

Then, uninstall the node

brew uninstall node

Installing Node with NVM

The version manager I'm going to use is nvm. I prefer its simplicity when it comes to managing node versions in my system.

First, go to https://github.com/nvm-sh/nvm to get the latest version when downloading and installing the package using curl. As of this writing, the version of nvm is 0.38.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/

The command will download the source code from github and save is to ~/.nvm. Then, it will add a source string to bash_profile. Since in my case I'm using zsh shell, I'm moving the source string to my .zshrc file.

This block of code should be in the .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

The next step is to restart the terminal with source ~/.zshrc

Installing a Node version

First, list all the node versions that are available: nvm ls-remote.

Then install the specific version (without the v prefix). For this article, I'm using the latest LTS version 14: nvm install 14.17.3.

After installation, the version will automatically be set as default.

Verify that the node version is installed: nvm ls.

Installing another Node version

Same steps above apply when installing a different Node version. In this case, I'm installing the latest LTS version 12: nvm install 12.22.2.

Switching from one Node version to another

Changing node version is as easy as: nvm use 14.17.3


This free site is ad-supported. Learn more