Installing NodeJS is not a complicated matter, but what if we need a specific version? or need to have several versions? So, in this post, you will learn how to install NVM on Debian 11.
According to the project’s Github profile:
nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: Unix, macOS, and windows WSL.
So in this way, we will be able to manage several versions of NodeJS on many systems like Linux, Windows, or macOS. Besides being open source it is very easy to use and having it at hand is a great idea.
Using NVM has some advantages that a developer should not overlook:
- With NVM you can install multiple versions of NodeJS and manage them easily.
- Thanks to NVM you can install a specific version of NodeJS, such as the latest stable version or the latest in the LTS series.
- By having several versions installed, we can define which one we will use by default.
So, NVM is available for Debian 11 so we can install it without any problems.
Install NVM on Debian 11
The recommended way to install NVM on any Linux system is to download and run the script provided by the developers. So, you can download it using either the wget
command or the curl
command, so you have a choice. You will also need to install the tar
command from the repositories.
sudo apt install curl wget tar
In this case, I will use wget
to download it. And in the same command, I will run it.
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
After the download and execution process is finished, we will have to refresh the changes in the bashrc
file.
source ~/.bashrc
Now NVM is ready and installed on the system.
Using NVM on Debian 11
To see all the versions of NodeJS that can be installed with NVM, you have to run it with the following command
nvm ls-remote
Sample Output
v14.17.3 (LTS: Fermium) v14.17.4 (LTS: Fermium) v14.17.5 (LTS: Fermium) v14.17.6 (LTS: Fermium) v14.18.0 (Latest LTS: Fermium) v15.0.0 v15.0.1 v15.1.0 v15.2.0 v15.2.1 v15.3.0 v15.4.0
Now install the version you want as follows
nvm install 15.0.1
Just replace 15.0.1
with the version number you want.
Also, you can install the latest stable version of NodeJS by simply running
nvm install node
It is recommended to work with LTS versions for support reasons. So, you can install the latest LTS stable version this way
nvm install lts/*
Either way, you will have NodeJS installed.
To check all the versions of NodeJS that you have installed on your system, you have to run
nvm ls
If you have multiple versions installed, you can set the default version as follows
nvm use [version]
And check the changes
nvm default --version
If you want to uninstall any version of NodeJS from the system, you have to run
nvm uninstall [version]
Removing NVM on Debian 11
If you no longer want to use NVM on Debian, you can uninstall it from the system. To do this, delete the NVM folder.
rm -rf "$NVM_DIR"
And edit the .bashrc
file.
nano ~/.bashrc
And delete the following lines
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion
So, save the changes and close the editor. Finally, refresh the changes in the file.
source ~/.bashrc
And there will be no trace of NVM left on the system.
Conclusion
NodeJS is very important in web development and that’s why you need a tool to manage multiple views and help developers with testing and so on.
So, what do you think about NVM? Leave us a comment and help us grow.