NVM Installation
NVM install and Manage Node.js version in the user’s home directory. So you don’t need any root-level privileges. Simply login as a non-root user and follow tutorial. The NVM team provides a Bash script for the installation of NVM on the Linux system. You can simply execute this script on your machine to install NVM. The installer makes an entry to the user’s default profile file. You need to reload the user’s environment using one of these commands. It will set the required environment variables to use nvm on the system.
Search Available Node.js Version’s
At this point, you have installed nvm on your system for the current user. Now find out the available version of Node.js to install. Use ls-remote option to list versions. You will see a long list of available Node.js versions. You can install any of the listed Node.js versions.
Install Multiple Node.js Versions
Now install the node.js version you need to use for running node.js application. Below command will install node.js v12.13.1 the LTS release on your system. You can have also installed the latest version of Node.js. Repeat the above command with the different-2 node.js versions to install multiple versions of node.js on your system. For this tutorial, I have installed both of the above Node.js version and one more old LTS version below: Now, I have installed 3 Node.js versions on my system.
Set Node.js Default Version
As you have installed multiple node.js versions, You can select the specific version of node.js as default version used by system and load in the environment. Use below command to list currently installed version and default set version. You can see that version 10.17.0 is set as the default Node.js version. Now, change the default Node.js version to 12.13.1. Now verify the currently active version of Node.js. Using the same command you can switch to any Node.js version any time as per your requirements. But still, there is a question. How can we run two or more applications with different Node.js versions at the same time? Not to worry, read the next step:
Runing Application with Specific Version
You want to run multiple Node.js applications on your system and want to run each with a specific version of node.js. NVM provides you an option to do this. You can use any installed node.js version for running a Node.js application. For example: The app.js will run with Node.js version 10.17.0, It doesn’t matter what is the default version is set on your system.
Remove Unused Node.js Version
This command will provide a list of installed versions of node.js on your system. Now remove any version installed on your system using the following command. The below command will remove Node.js version 10.16.3 from your system.
Conclusion
This tutorial helps you with the installation of multiple Node.js versions on the Linux machine. Follow our next tutorial to deploy Node.js application with PM2. The PM2 helps you to keep any Node.js application run. In case the application goes down for any reason PM2 will start it automatically.