header banner
Default

Method for Reverting to an Older Node NVM-Based Version of JavaScript


Downgrading software can be every bit as challenging as upgrading it, but not with NVM. This tool makes it easy to switch your Node.js version.

a person holding a Node.js sticker

With the release of new Node.js versions, it’s not uncommon for you to encounter compatibility issues with the existing dependencies. In such cases, you may need to downgrade the Node.js version you’re using to a more suitable one to ensure your application works as expected.

Learn about the steps you should take to downgrade your version of Node.js.

Understanding the Node.js Versioning System

Not all Node.js releases are equal. While newer versions offer improved performance and new features, they may also introduce breaking changes that could cause issues with your code. When choosing a previous version, select the one that’s stable and compatible with the dependencies you’re using in your app.

LTS releases are versions that are supported for an extended period and receive regular updates, including security fixes and bug patches. Current releases, on the other hand, are intended for developers who want to use the latest features and improvements. When choosing a Node.js version to use, keep this in mind.

Using NVM to Manage Node.js Versions

The Node Version Manager (NVM) lets you install and switch between multiple Node.js versions with ease. It lets you install packages and dependencies specific to each Node.js version. This means that you can have different sets of packages and dependencies for each project, depending on the Node.js version it requires.

This approach is better than installing and uninstalling Node every time you need a specific version.

Before using NVM, you must install it. Visit the official NVM GitHub repository and follow the instructions to install NVM in your operating system.

After installing NVM, verify that it’s working correctly by running this command:

 nvm --v

If you’re on Windows, you may need to restart the operating system or run this command as an administrator on the command prompt.

Now that you have NVM installed, you can use it to manage your Node.js versions. The following are basic steps to install Node.js version 17.9.1.

Open a terminal or command prompt. Then, use the nvm install command followed by version number 17.9.1.

 nvm install 17.9.1

Once the installation is complete, use the command nvm use followed by the version number to switch to the installed Node.js version.

 nvm use 17.9.1

Verify that the correct Node.js version is being used by running the command node -v in the terminal or command prompt:

 node -v

This should display the version number of the Node.js version you just installed.

 v17.9.1

Switching Between NVM Versions

As previously stated, one of the main advantages of using NVM is the ability to easily switch between Node.js versions as needed.

To get started, use the nvm ls command to list all the Node.js versions installed on your machine.

 nvm ls

The output of the nvm ls command includes the version number and whether that version is currently in use.

 20.1.0
18.12.1
* 17.9.1 (Currently using 64-bit executable)
6.14.0

You can now use the command nvm use followed by the version number to downgrade to the desired Node.js version.

Creating an Alias for Node.js Versions

If you frequently reference a certain Node.js version for your projects, you may find a short alias easier to remember and type.

To create an alias for a specific version of Node.js using NVM, use the nvm alias command. For example, to create an alias called default17 for Node.js version 17.9.1, run the following command:

 nvm alias default17 17.9.1

Now, instead of typing out nvm use 17.9.1 every time you want to switch to that version, you can use nvm use default17.

If you want to remove this alias, use the nvm unalias command:

 nvm unalias default17

Using NVM to Manage Node.js Versions

Different applications may be compatible with different Node.js versions. If you need to downgrade to a previous version or even upgrade to the latest one, use NVM.

NVM will help you install multiple Node.js versions and switch between them on a per-project basis. This way, you avoid any incompatibility issues.

Sources


Article information

Author: Christopher Guzman

Last Updated: 1704168005

Views: 698

Rating: 3.7 / 5 (36 voted)

Reviews: 97% of readers found this page helpful

Author information

Name: Christopher Guzman

Birthday: 1922-10-27

Address: 25351 Matthew Mountains Suite 142, West Richard, VT 21267

Phone: +3916796471711758

Job: Interior Designer

Hobby: Woodworking, Wine Tasting, Orienteering, Meditation, Basketball, Cooking, Coffee Roasting

Introduction: My name is Christopher Guzman, I am a dear, courageous, honest, frank, daring, expert, esteemed person who loves writing and wants to share my knowledge and understanding with you.