How to install or switch between different node versions

  #nodejs  #web-dev  

If you work on NodeJS or use it to build front web web apps, chances are you may need different versions of node. Alternate versions of Node would sometimes be ideal, either for different projects or to test the features or packages that might make or break with the newer versions of NodeJs.

It is quite easier to install, maintain and switch between various versions of NodeJS on your system. We'll use nvm or 'Node Version Manager" to achieve this.

Get 'NVM' or 'Node Version Manager' installed.

To manage different versions of node, we'll make use of 'nvm' or Node Version Manager.

Nvm installation on Mac without npm

If you do happen to use a Mac and have the now defaulted 'ZSH' Shell, you'll need to make sure you have the .zshrc profile. For non mac systems, skip to the subsection of installing nvm.

Check if you do have the .zshrc profile already avaliable. This can be tested by running the below command at the terminal and looking for the .zshrc file.

  ls -a

If you do see the file, it's all good and you can move ahead to install the nvm package.

If not, create a new .zshrc profile file by running the below command at the terminal- at the user's home folder.

  touch .zshrc

After the .zshrc profile is setup, you can now use curl or wget to pull the nvm installer.

Example below

  curl -o- | bash
  wget -qO- | bash

More details or verification of the url to pull nvm installer can be checked on NVM's Github page.

If you do not wish to restart the terminal, you will have to fire the below command to use the latest updates from your .zshrc profile file.

  source .zshrc

Installing nvm on windows without npm

On an window's system, you can proceed to install nvm using the nvm installer from this link and then continue to next section to install nvm using nvm.

Using nvm to install Node

Now after the nvm or node version manager package is successfully installed, we can install nodejs. Before we do that, let's make sure our nvm is all good by checking the version number using the below command.

  nvm -v

If you do see a version number, it's all good to now continue. If not, look for any errors during your nvm installation and try again.

In order to see the list of all avaliable node versions:

  nvm ls

You may either have none installed or this command will display the list of all the node versions on your system.

In order to install the latest long term supported version of node, use the below command

 nvm install --lts

In order to look up all the avaliable node versions :

  nvm ls-remote

In order to install a specific version of node

  nvm install <VERSION_NUMBER>


   nvm install 18.7.0

Once you have multiple versions of node and wish to use a specific one, you may use the below command by specifying the version number.

  nvm use <VERION_NUMBER>


  nvm use 18.0.0

Checking other avaliable commands with nvm:

  nvm help

If you find this article helpful, please consider sharing! Thanks for reading :)