in Javascript

Install Node With NVM

The NVM (Node Version Manager) is a script used for installing and managing Node. The macOS users can install NVM using the homebrew.

Use this tutorial to help install NVM on your mac and manage Node.js versions.

First remove the installed node version.

brew uninstall --ignore-dependencies node 
brew uninstall --force node 

Next install NVM

brew update
brew install nvm

Create a directory for the nvm config

mkdir ~/.nvm 

We need to add the environment variables to the bash profile you use such as ~/.zshrc

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/

Reset your shell environment.

source ~/.zshrc

Check that nvm is installed.

nvm ls-remote

Install Node

With NVM installed we can now install node.

nvm instal node # install the latest version
nvm install 16 # install a specific version of node

Check node version is installed

node -v

Set Default Node Version

To set a default node version with NVM you can use the following command

nvm alias default <version>

To automatically use the right version to suit the project's package.json file you can use.

nvm use