How to Install npm on Debian 12: 5 Easy Methods

Install npm on Debian 12

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
using the Debian default repository to install Node.js in Debian 12

After the installation process is complete, check the Node.js version for confirmation:

node -v
Validating the installation using the deb repository

To use JavaScript packages on Debian 12, first, install npm (Node Package Manager) with:

sudo apt install npm -y
installing npm package manager

You can also check its version by using this command:

npm -v
verifying the installtion of npm

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
installing the node version manager on Debian using the GitHub bash file for NVM

After that, insert the NVM script into the path using:

source ~/.profile
executing source command to add the NVM script in the path

NVM includes all versions of Node.js. To view all the versions of Node.js, run:

nvm ls-remote
listing all the version of Node

To install the latest version of Node.js (that is 22.7.0), execute:

nvm install [preferred node.js version]
installing node.js latest 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 -
downloading and executing deb repository in the bash shell

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
installing through debian apt package manager

Lastly, confirm the installation of Node.js using:

node -v
Validating the installation using the deb repository

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:

click on download option for downloading node.js

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
extracting the content using the tar command

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
Launching Node js on debian

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
installing Node.js on Debian using the Snap package manager

If you want to check whether Node.js is successfully installed or not on Debian 12, run this command:

sudo snap list
validating the installation of node js via snap

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 a Reply

Your email address will not be published. Required fields are marked *