How to maintain multiple nodes versions in Linux Ubuntu 22

navya , Credit to  volkotech-solutions Jul 23

We can keep multiple node versions in Ubuntu 22 without deleting others, and we can easily switch the versions as needed. Here is the trick, get it.

Firstly, we have to know which node version will support which framework, for example, gulp will work only with node version 14, and some Reactjs packages need an advanced version. So if you are in a situation where you need both versions, then here is the solution to face this situation.

Install nvm

We can install multiple versions of a node using node version manager(nvm), make sure you have installed nvm in your Ubuntu if not you can install it with the following command.

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

We have used curl to install nvm if you don’t have a curl then click here How to install curl in Ubuntu via the command line

installing nvm with curl

Then After the installation script finishes running, close and reopen your terminal or run the following command to refresh the terminal

$ source ~/.bashrc

Replace ~/.bashrc with the appropriate configuration file for your shell if you are using a different shell (e.g., ~/.zshrc for Zsh).

List node versions

Now with the following command, just list the available node versions in your Ubuntu

$ nvm ls-remote

Here are available versions of node in my machine.

list of available node versions

Install the required node version

Now we can install the required node version as per the need with the following command

$ nvm install node_version
# $ nvm install 18

Here is the screenshot for your reference

installing the required version node with nvm

After installing the required node version, then we need to set the node version with respect to the project we need, and here is the command

$ nvm use node_version
# $ nvm use 18

Here is the screenshot for your reference,

setting the node version

Switch node version

We can easily switch node versions as we have nvm, here is the command to switch the node version. Just do nvm install and set another node version whatever is required.

For example, if I need to use gulp in my project, then gulp will support only node version 14, so it is better to switch the node versions instead of deleting previous versions and installing new ones. Here is the screenshot for reference

switching node version

Conclusion

As per the above steps, we can manage multiple versions of a node with the help of the node version manager(nvm). Hope this article full fills the requirement, Happy learning!!

Comments

Authors

Read Next