macbook setup

Installing Node using NVM on Mac

install nodejs

install nodejs

When working with NodeJs application we may want to use different Node versions but this is a cumbersome task and here comes the use of NVM.
NVM as the name says Node Version Manager, is a version manager for node.js which allows you to easily switch between Node versions, which is essential. You can install different versions of node and switch anytime between those versions with just a command line.

Installing NVM on mac OSX

installing is pretty simple just you need to run the install script as shown below

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

The above command downloads a script and runs it. The script clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile~/.zshrc~/.profile, or ~/.bashrc).

Checking NVM install

To check wether NVM was installed properly, try to run below command

nvm --version

You will get to see the nvm version installed on the system as shown in the below screenshot.

Troubleshooting

After installing nvm if you get to see nvm not found error as shown below

This could be due to possibly due to 2 problems:

  1. Either NVM is not installed properly
    For this go to your home folder (~ or $HOME) and check if a .nvm folder exists there.
     ~/.nvm/nvm.sh
  2. NVM path is not set
    For this open (~/.bash_profile~/.zshrc~/.profile, or ~/.bashrc) whichever shell you are using and to the bottom of the file add below line.
    source ~/.nvm/nvm.sh

Installing Node

To install the latest node version, run below command

nvm install node

To install the recent LTS node version, run below command

nvm install --lts

To install any specific version let say 12.18.3 in our case, run below command

nvm install 12.18.3

Other NVM commands

To check installed node version via NVM

nvm ls

Switch between node version, let say we want to switch to 12.18.3

nvm use 12.18.3

NVM also has a default version which means that if you start your terminal fresh instance then your default node version will be used automatically.
By default, the 1st installed node is your default node version in NVM.

To change your default node version in NVM, let say we want to set 12.18.3 as the default node, then run

nvm alias default 12.18.3

Leave a Reply

Close Bitnami banner
Bitnami