How to Install and Use NVM on Debian 11

NVM is a version manager for Node.js used to install and manage multiple Node.js versions in Linux. It is a command-line utility and provides several options for the easy installation of Node.js. It allows you to download and install any version of Node locally with a simple command.

In this post, we will show you how to install and use NVM to manage Node.js on Debian 11.

Prerequisites

  • A server running Debian 11.
  • A root password is configured on the server.

Install NVM

The installation of NVM is a very straightforward process. You can simply install it using the CURL command.

First, install the CURL and Gnupg2 with the following command:

apt-get install curl gnupg2 -y

Next, run the following command to download and run the NVM installation script:

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

The above command will install NVM and makes all the required environment settings in the .bashrc file.

Now, activate all settings using the following command:

source ~/.bashrc

Now, verify the NVM version using the following command:

nvm --version

You should see the following output:

0.38.0

Install Node.js with NVM

At this point, NVM is installed in your system. You can now install any Node.js version to your system.

To install the latest version of Node.js, run the following command:

nvm install node

You should see the following output:

Downloading and installing node v16.9.0...
Downloading https://nodejs.org/dist/v16.9.0/node-v16.9.0-linux-x64.tar.xz...
######################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.9.0 (npm v7.21.1)
Creating default alias: default -> node (-> v16.9.0)

To verify the installed version of Node.js, run the following command:

node --version

You should see the following output:

v16.9.0

If you want to install the latest stable version of Node.js run the following command:

nvm install node --lts

You should see the following output:

v16.9.0 is already installed.
Now using node v16.9.0 (npm v7.21.1)

To install the specific Node.js version (12.17.0), run the following command:

nvm install 12.17.0

You should see the following output:

Downloading and installing node v12.17.0...
Downloading https://nodejs.org/dist/v12.17.0/node-v12.17.0-linux-x64.tar.xz...
######################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.17.0 (npm v6.14.4)

Now, verify the current Node.js version using the following command:

node --version

You should see the following output:

v12.17.0

Use NVM to Manage Node.js Versions

To list all installed Node.js versions in your system, run the following command:

nvm ls

You should see the following output:

->     v12.17.0
        v16.9.0
default -> node (-> v16.9.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.9.0) (default)
stable -> 16.9 (-> v16.9.0) (default)
lts/* -> lts/fermium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.6 (-> N/A)
lts/fermium -> v14.17.6 (-> N/A)

You can find the all available Node.js versions using the following command:

nvm ls-remote

To set your default Node.js version to 12.17.0, run the following command:

nvm use 12.17.0

You should see the following output:

Now using node v12.17.0 (npm v6.14.4)

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

nvm run default --version

You should see the following output:

Running node v16.9.0 (npm v7.21.1)
v16.9.0

You can also run a Node application with a specific Node.js version using the following command:

nvm run v12.17.0 app.js

To remove a specific Node.js version from your system, run the following command:

nvm uninstall v12.17.0

Conclusion

In this post, we explained how to install NVM to install Node.js on Debian 11. We also explained how to switch between multiple Node.js versions using NVM. I hope you can now run your application with any Node.js versions.

Share this page:

Suggested articles

0 Comment(s)

Add comment