How to Downgrade to a Previous Node.js Version Using NVM

Introduction

Before we discuss how to downgrade to a previous Node.js version using NVM, let's first understand-What is NVM?

Node.js Version Manager (NVM) is a helpful tool for managing different versions of Node.js on your system. If you need to downgrade to a previous Node.js version using NVM.

This tutorial will provide step-by-step instructions to help you accomplish that. We will also address few FAQs to downgrade to previous Node.js version using NVM.

Advantages

  1. Flexibility: NVM allows you to switch between different Node.js versions effortlessly, giving you the flexibility to use the version that best suits your project's requirements.
  2. Multiple Environments: With NVM, you can set up multiple Node.js environments on the same system, each with its own Node.js version and installed packages.
  3. Simplified Version Management: NVM simplifies the process of installing, managing, and switching between Node.js versions, making it easier to maintain different projects with specific version dependencies.
  4. Easy Upgrades and Downgrades: NVM provides a straightforward way to upgrade or downgrade to different Node.js versions, ensuring compatibility with your application's dependencies.
  5. Community Support: NVM has a thriving community, which means there are ample resources, tutorials, and support available if you encounter any issues or have questions.

How to Downgrade Node Version on Ubuntu?

To downgrade the node version on Ubuntu, use the n command. This command installs, activates, and removes the node version immediately. Moreover, it can also manage the different node versions in the Linux operating systems easily.

This section carries out the practical implementation of n command to downgrade the node version on Ubuntu using the given steps of instructions.

Step 1: Check Node Version
Firstly, check out the already installed node version by specifying its name like node with the "version(v)" flag:

node -v

The installed node version is v18.20.4:

Step 2: Install n in Ubuntu
Next, execute the following installation command with the administrative privileges to install the n command globally in the Ubuntu system:

sudo npm install -g n

In the above command, the npm keyword refers to the "node package manager" and the sudo denotes the administrator.

The following output confirms that the n package has been added to the current OS:

Step 3: Install Downgrade Node Version
Now, use the n command to install any older/downgrade node version in the Ubuntu operating system:

sudo n 10.16.0

Here, the output shows that the specified node version has been installed successfully in Ubuntu. Now, the current Ubuntu OS maintains both older and newly installed node versions placed at the specified path:

In the above output, the purpose and use of the highlight hash -r command are discussed in the next step.

Step 4: Verify Downgraded Node.js Version
Before the verification of a newly installed node, it is recommended to start a new shell or reset the location of the node using the hash command along with the r flag. It forgets all the remembered location from the hash table because the current shell will not show the newly installed node version until it clears the existing node location:

hash -r
node -v //Checking Node version

After clearing the hash table of the current Ubuntu system, the version command shows the newly installed downgraded version of the node:

Hence, it is verified that the node v18.20.4 version has been downgraded to v10.16.0.

That’s all about downgrading the Node version on Ubuntu.

FAQs to Downgrade Node.js using NVM

How can I install a specific Node.js version using NVM?

To install a specific Node.js version, run nvm install <version>. For example, nvm install 12.22.6 installs Node.js version 12.22.6.

How do I switch to a different Node.js version after installation?

Use the command nvm use <version> to switch to a specific Node.js version. For instance, nvm use 14.17.6 will set Node.js version 14.17.6 as the active version.

Can I have multiple Node.js versions installed concurrently with NVM?

Yes, NVM allows you to have multiple Node.js versions installed concurrently, enabling you to switch between them as needed.

How do I downgrade to a previous Node.js version using NVM?

First, check the available Node.js versions using nvm ls-remote. Then, install the desired previous version using nvm install <version>. Finally, switch to that version with nvm use <version>.

How can I uninstall an old Node.js version installed via NVM?

Run nvm uninstall <version> to remove a specific Node.js version. For example, nvm uninstall 12.22.6 uninstalls Node.js version 12.22.6.

Can I use NVM on Windows?

Yes, NVM works on Windows and other operating systems. However, note that for Windows, you may need to use an alternative like nvm-windows (https://github.com/coreybutler/nvm-windows).

Can I specify a default Node.js version with NVM?

Yes, you can set a default Node.js version using nvm alias default <version>. This version will be automatically used when you open a new terminal session.

Conclusion

To downgrade the node version on Ubuntu, use the n command. It is not the built-in command, so the user first needs to install it into the Ubuntu OS through the npm package manager and then utilize it for downgrading the node version. It switches the node version in the form of enhancement or downgradation.

This tutorial has described the complete procedure to downgrade the node version using nvm.