What news from AWS re:Invent last week will have the most impact on you?
Amazon Q, an AI chatbot for explaining how AWS works.
Super-fast S3 Express storage.
New Graviton 4 processor instances.
Emily Freeman leaving AWS.
I don't use AWS, so none of this will affect me.
Additional Resources / Operations

NVM: Manage Multiple Versions of Node.js on a Single System

With NVM, you can install as many versions of Node.js as needed and switch back and forth between versions with ease.
Oct 7th, 2023 6:00am by
Featued image for: NVM: Manage Multiple Versions of Node.js on a Single System
Feature Image by Heejin Jeong from Pixabay.

Developers often have to depend on multiple versions of the same language, framework, or library. This can happen because one project might depend on the latest version of a language, whereas another project might require a previous release.

Some operating systems and/or languages don’t make the task of using multiple versions of the same language easy. If you happen to use Linux as your development platform and Node.js as one of the many languages you work with, you’re in luck, as there’s a handy tool to make this fairly simple.

The tool in question is called NVM, which stands for Node Version Manager. NVM can be installed on many different Linux distributions, such as Ubuntu, RHEL, CentOS Stream, Rocky Linux, AlmaLinux, and Debian, as well as MacOS and Windows (via Windows Subsystem for Linux).

Essentially, NVM is a version manager for Node.js that is installed on a per-user basis and is invoked from the command line on any POSIX-compliant shell (such as sh, dash, ksh, zsh, and bash).

I’m going to show you how to install and use NVM on Ubuntu Server 22.04.3 and Rocky Linux 9.

What You’ll Need

To use NVM, you’ll need the following:

  • Either an instance of Ubuntu or Rocky Linux (or another equivalent, such as AlmaLinux or CentOS Stream).
  • Node.js installed.
  • A user with sudo privileges.
  • A network connection.

That’s it. Let’s get to work.

Installing NVM on Ubuntu Server

Log into your Ubuntu Server instance. If your server includes a desktop environment, open a terminal window.

The next step is to install a few dependencies, which can be done with a single command:

Next, download and run the installation script with the command:

Once the command completes, log out and log back into your Ubuntu server instance.

Installing NVM on Rocky Linux (or an Equivalent Distribution)

The installation of NVM on Rocky Linux is similar to that of Ubuntu, the only difference being the installation of the dependencies.

To install the dependencies, log into your Rocky Linux instance and, if necessary, open a terminal window. Then, issue the following command to install the dependencies:

The installation of the dependencies will take considerably longer on Rocky Linux than it does on Ubuntu. When it completes, you can then issue the same install command on Rocky Linux as you did Ubuntu, which is:

When the command completes, log out of Rocky Linux and log back in. You can then verify the installation with the command:

The output should be something like this:

NVM is now installed and ready to use.

If you find the prompt returns that NVM isn’t installed, you might have to reload your .bashrc script with the command:

Installing Node.js with NVM

Now that NVM is installed, you can use it to install different versions of Node.js. This process is the same, regardless of which distribution you are using. With NVM, you’ll find it possible to install Node.js versions from v0.1.14 all the way to v20.7.0. Of course, you probably won’t want to go all the way back to beta releases and as Node.js is upgraded, newer releases will be added.

To find the complete list of available Node.js releases for NVM, issue the command:

The output will look something like this:

Let’s say your current project requires Node.js version 19.0.1. To install this version, the command would be:

When the command completes, you can verify the installation with the command:

You should see the following output:

->      v19.0.1
default -> v19.0.1

If you’ve installed Node.js from your default package manager (such as apt-get), you might see a system entry in the output. If you want to use the version of Node.js installed by the system, you could issue the command:

If you have multiple versions of Node.js installed, you can choose which one to use with a command like:

The output for the above command will look like this:

With NVM, you can install as many versions of Node.js as needed and switch back and forth between versions with ease. Any time a project demands a different release, switch with the nvm use command and you’re good to go.

Group Created with Sketch.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.