npm (Node Package Manager) is an important tool that allows you to install and manage JavaScript libraries and packages on Debian 12. However, if you want to use npm, it is required to install Node.js first. Resultantly, it provides the run time environment to execute JavaScript on the server side.
Installing Node.js offers several other benefits as well. For example, it not only gives you access to a wide range of libraries and tools through npm but also ensures that you have the necessary runtime to execute server-side JavaScript. Moreover, it helps to boost performance for real-time applications.
Method 1: Installing Node.js and npm Using Debian
Installing Node.js and npm through the Debian package manager is one of the easiest methods. To get started, first, install Node.js on your Debian system.
Note: This method installs an older version of Node.js on your system:
sudo apt install nodejs -y
After the installation process is complete, check the Node.js version for confirmation:
node -v
To use JavaScript packages on Debian 12, first, install npm (Node Package Manager) with:
sudo apt install npm -y
You can also check its version by using this command:
npm -v
Method 02: Installing NVM (Node Version Manager) Using Curl Script
NVM allows you to install many different versions of Node.js on Debian 12. One of its major advantages is switching between other versions of Node.js. For that, install NVM on your system using GitHub file as indicated below:
curl-o-https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
After that, insert the NVM script into the path using:
source ~/.profile
NVM includes all versions of Node.js. To view all the versions of Node.js, run:
nvm ls-remote
To install the latest version of Node.js (that is 22.7.0), execute:
nvm install [preferred node.js version]
Method 3: Installing npm Using Node.js Deb Repository
The official Debian library comprises over 20 versions of Node.js. Now, let’s download and run a setup script from NodeSource to install Node.js version 20. x and npm on a Debian system:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -
After that, install Node.js on Debian 12 which won’t require any additional input during the installation process:
sudo apt-get install -y nodejs
Lastly, confirm the installation of Node.js using:
node -v
Method 04: Installing Node.js Pre-Built Binaries
Another simple method to install Node.js on Debian 12 is using its prebuilt binaries by downloading the file and executing it.
For this, visit the Node.js download page, choose your preferred version, and click the Download button:
Now, run the tar command for the extraction of the downloaded Node.js package:
sudo tar -xvf node-v22.7.0-linux-x64.tar.xz
Note: You can add the desired Node.js version in the above command.
Then, start Node.js on Debian 12 by navigating to the ‘bin’ directory, and use the below command to run the binary file:
./node
Method 05: Installing Node.js Using Snap
In this guide, the final method to install Node.js on Debian 12 is through the snap package manager. To do so, execute this command on the terminal:
sudo snap install node --channel=22/stable --classic
If you want to check whether Node.js is successfully installed or not on Debian 12, run this command:
sudo snap list
This command opens up a list of all the applications that are installed using this package manager.
Conclusion
This guide has covered the most simple methods for installing Node.js and npm on Debian 12.
For instance, the Debian package manager offers the easiest way to install Node.js, while Node Version Manager (NVM) provides a variety of Node.js versions. Also, if you want to install a specific version of Node.js on Debian 12, then try the prebuilt binaries approach. Additionally, you can go for curl and snap methods.
You can choose any of these methods to install Node.js and npm on Debian 12 according to your preferences.
Leave feedback about this