Installing Node.js and NPM on Debian 11 became so easier using Node Version Manager (NVM). This is a tool that can be installed per-user and invoked per-shell basis. You can install and switch between multiple Node.js versions easily.
In this guide you are going to learn how to install Node.js and NPM, manage multiple versions, uninstall versions using Node Version Manager.
Pre Installation Steps
Start by updating and upgrading the server packages to the latest version available.
sudo apt update sudo apt dist-upgrade -y
Install NVM
You can copy the link for the latest NVM installation bash script directly from their official repository. The version available at the time of this article writing is v0.39.1
.
Switch to the user on which you need to use Node.js.
sudo su username
Execute the following command to install NVM.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
This command downloads the installation script and runs it.
For the nvm command to be available you need to close the terminal and open again or you can simply execute the following command to make it available in your current session.
source ~/.bashrc
Verify the Installation
You can verify the installation using the below command.
command -v nvm
output
nvm
Install Node.js
You can check all available Node.js versions using the following command.
nvm ls-remote
output
. . .
v16.13.0 (LTS: Gallium)
v16.13.1 (LTS: Gallium)
v16.13.2 (Latest LTS: Gallium)
v17.0.0
v17.0.1
v17.1.0
. . .
You can pick any specific version to install.
nvm install v16.13.2
This command installs Node.js and the related NPM.
Check Node.js version.
node -v
output
v16.13.2
Manage Node.js versions using NVM
You can list all installed Node.js versions using the ls
command.
nvm ls
You can install multiple Node.js versions using the install command.
You can switch between versions using the use
command.
nvm use v14.18.3
You can uninstall a specific version using the uninstall
command.
nvm uninstall v16.13.2
Become a Full-Stack Web Developer with React Specialization. Complete Web Development Course
Uninstall NVM
To remove nvm
, execute the following:
$ rm -rf "$NVM_DIR"
Edit ~/.bashrc
or other relevant shell resource config and remove the lines below.
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
That’s it. Now you have installed Node.js and NPM on Debian 11.
Conclusion
Now you have learned how to install, manage and uninstall Node.js on Debian 11 using NVM.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.