If you have ever had trouble running a project because you do not have a compatible version of Node.js installed, then you are not alone. Fortunately, there is an easy fix to this problem.

With Node Version Manager (NVM), you can install several versions of Node.js on your machine and choose which version you wish to use depending on the project you want to run.

NVM is an open-source project that aims to ease out the installation and management process of Node.js.

What Is Node.js?

Node.js is an open-source and cross-platform JavaScript runtime environment that is built on Google Chrome's V8 Engine. Node.js allows you to run and execute JavaScript code outside of a web browser, which in turn allows you to build and run both front-end and back-end applications with JavaScript code on your PC or server.

Popular front-end web frameworks that make use of Node.js include Angular and React. Remember, Node.js can also be used for developing back-end or full-stack applications; popular back-end frameworks using Node.js include Express.js, Meteor.js, Nest.js, and Hapi.js.

Related: Front-End vs. Back-End Web Development: Which Path Is Right for You?

Due to the wide popularity of JavaScript for programming, Node.js has become an important component in software development and Linux administration for servers running JavaScript applications.

Installing NVM in Linux

Installing NVM in Linux is pretty straightforward. Open up your terminal and run the following command.

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

The aforementioned command will run a script that downloads and installs NVM. In addition, it will also set a profile for NVM in your environment variable. In this case, the .bashrc file as you can see from the installation output below.

nvm installation output

The environment variable file is located in either of these locations: ~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc depending on the Linux distro that you are using.

Verifying the Installation

Note: Before you can proceed to check if the installation was successful, close your current terminal, and open a new terminal window. Alternatively, you can open another terminal window by pressing Ctrl + Alt + T on the keyboard.

In the new terminal window, you can check if NVM is successfully installed by running the following command.

        command -v nvm
    

If everything went well, the output from the command above will be nvm as shown below.

Output from nvm installation confirmation

To check the version of NVM installed on your PC, you can run the following.

        nvm -v
    

Installing Node.js

Installing Node.js with NVM is very easy. For example, to install the latest version of Node.js, you can run the following command:

        nvm install node
    

To install some specific version of Node.js, you can run the nvm command in the following format:

        nvm install version-number
    

For example, to install Node.js version 14.15.4:

        nvm install 14.15.4
    

Node.js version 14.15.4 is an LTS version of Node.js.

If you have come this far and have issued the two commands above, congratulations! You have two different versions of Node.js installed on your PC or server.

Selecting the Version of Node.js To Use

When you have multiple versions of Node.js installed, you can easily choose the version of Node.js that you wish to use. For example, to use version 14.15.4 that you recently installed, you can run the following command.

        nvm use 14.15.4
    

To view the list of Node.js versions installed on your PC, you can run the command below.

        nvm ls
    

The output of the listing is similar to the one below. The currently active version is also highlighted.

output showing all installed versions of nodejs on a PC

To list all versions of Node.js available for installation, you can run:

        nvm ls-remote
    

Uninstalling Node.js

Uninstalling a version of Node.js via NVM is very simple. For example, to uninstall version 14.15.4 that you installed above:

        nvm uninstall v14.15.4
    

Getting Help

To learn more about NVM commands or to get help, simply type the following command:

        nvm -h
    

You can also visit NVMs' official GitHub page, which is well documented.

Node.js Management Simplified

This guide has shown you how to install Node Version Manager (NVM) to ease out the management and installation of Node.js. If you have projects that use different versions of Node.js, then NVM is the tool for you. It will simply make your life easier.

Reusability is one of the most important programming paradigms that should be followed by everyone. Luckily, in JavaScript, you can easily create reusable code using Design Patterns.