Install and Use NVM on Debian 11

NVM stands for Node Version Manager which is a command-line tool used to install and manage multiple Node.JS versions. You can have multiple installations of Node.JS in a single account and decide which version to use for your project. The installation of Node.JS is user account specific and other user accounts can have their own independent installations.

There are different ways of installing Node.JS. One of them is to use the APT package manager which installs it from Debian repositories. However, this does not always install the latest version. Another way of installing NodeJS is using the NVM utility.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Node.JS queries.

In this context, we shall look into the process of installing NVM on Debian 11.

Different ways to install NVM on Debian

1. Download and install the NVM utility

To install NVM, you need to, first, download and run the NVM bash script as follows:

$ curl | bash 

The command downloads nvm as a script to the .nvm folder in the home directory. It then appends the environment variables for NVM in the .bashrc file.

Next, reload the .bashrc file to apply the changes:

$ source ~/.bashrc

Alternatively, simply log out and log in again and confirm the version of NVM installed:

$ nvm --version

2. Install and Manage NodeJS using NVM

As mentioned earlier, NVM allows developers to install multiple versions of Node.JS. To install the most recent version of NodeJS run the following command with 'node' as the alias for the latest version:

$ nvm install node

If you want to install the latest LTS (Long Term Service ) version, run the command:

$ nvm install node --lts

In our case, the latest version – v16.10.0 – is already installed.

You can also specify a specific version of NodeJS by specifying the version number. Here, we are installing Node.JS v14.18.0:

$ nvm install 14.18.0

To list all the versions of Node.JS installed, execute:

$ nvm ls

To switch to a particular Node.JS version run the command as shown. Here, we are switching to Node v16.10.0:

$ nvm use 16.10.0

To verify the default version already set in your account, run:

$ nvm run default --version

You can list all the available Node.JS versions which are available for download with the below command:

$ nvm ls-remote

Finally, you can execute a Node.JS script with your preferred version with the below command:

$ nvm exec 14.18.0 backoffice.js

[Need assistance in configuring Node JS on your Linux system ? We can help you. ]

This article covers the basic nvm commands that you can use to install and manage multiple versions of Node.JS. In fact, Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

You can use the following command to list installed version's of Node for the current user:

$ nvm ls 

With this command you can find available Node.js version for the installation:

$ nvm ls-remote 

To find the default Node version set for the current user, run the command:

$ nvm run default --version 

Related Posts