Debian

How to Install and Use NVM on Debian 11

How to Install and Use NVM on Debian 11

There are several 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. NVM, short of Node Version Manager 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.

In this guide, we will walk you through the installation of NVM on Debian 11

Step 1: Download and install the NVM utility

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

$ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | 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

Step 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 as shown.

$ nvm ls-remote

Lastly, you can execute a Node.JS script with your preferred version as shown.

$ nvm exec 14.18.0 backoffice.js

Those are the basic nvm commands that you can use to install and manage multiple versions of Node.JS. We hope you found this insightful.

Similar Posts