Node Version Manager (NVM) is a versatile tool for managing multiple versions of Node.js on a single machine. It’s an essential tool for any serious Node.js developer since it allows you to switch between different versions of Node.js without having to go through the hassle of installing or uninstalling Node.js manually each time.
This article will guide you step-by-step through the process of installing NVM on Debian 12. But before we begin, it’s important to clarify that this guide assumes you have sudo privileges. If not, you might need to adjust the instructions accordingly or seek assistance from your system administrator.
Step 1: Update Your System
Before you begin, it’s a good practice to update your system’s package repository. Open a terminal and run the following commands:
sudo apt update
sudo apt upgrade
The apt update command updates the package list from the repositories, and the apt upgrade command upgrades all upgradable packages.
Step 2: Install Required Packages
The installation of NVM requires the build-essential and libssl-dev packages. These can be installed by running the following command:
sudo apt install build-essential libssl-dev
Step 3: Download and Install NVM
The preferred method for installing NVM is via the curl command, as it will always download the latest available version. Run the following command to download and install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
Once the command has been executed, the script will clone the NVM repository to ~/.nvm, and it will add the source lines to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
You may need to source that file to activate its environment for the first time:
source ~/.bashrc
To verify that the installation was successful, close your terminal and open a new one, then type the following command:
command -v nvm
If the installation was successful, nvm should be output.
Step 4: Using NVM
NVM is a command-line utility. Here are some examples of how you might use it.
To install a specific version of Node.js, you would use the nvm install command, followed by the version number. For example, to install Node.js 18, you would type:
nvm install 18
To use a specific version of Node.js, you would use the nvm use command, followed by the version number. For example, to switch to Node.js 18, you would type:
nvm use 18
And that’s it! You’ve successfully installed NVM on Debian 12. Now you can manage multiple versions of Node.js efficiently on your machine.
Conclusion
NVM is a valuable tool for Node.js developers, allowing for easy switching between Node versions and ensuring that all your projects have the correct dependencies. This guide has taken you through all the steps necessary to install NVM on Debian 12. Whether you’re an experienced developer or just starting out, NVM can help make your Node.js development process smoother and more efficient.