How to Install Node.js and NPM on Debian 12?
Introduction
Node.js as a runtime environment for executing JavaScript out of the browser has become quite popular, especially for developing backend, web apps, and scalable network applications. In conjunction with it comes NPM (Node Package Manager) as an advanced tool for dependency and package management for better control in the hands of developers.
If you are on Debian 12 and want to install Node.js on Debian or install NPM Debian, this guide will walk you through the installation methods using default repositories, NodeSource, or NVM (Node Version Manager).
Why Install Node.js and NPM on a Debian 12 system?
Installing Node.js and NPM on a Debian 12 system has several benefits:
- JavaScript Runtime Environment: It allows developers to run JavaScript code outside a browser.
- Backend Development: Essential for frameworks like Express.js, Nest.js, and many others.
- Package Management: NPM provides access to a great ecosystem of JavaScript libraries and tools.
- Cross-Platform Compatibility: It works seamlessly across operating systems.
Go through our article on What is npm
Installing Node.js and NPM
Let’s have a quick glance at a few steps to install Node.js and NPM on Debian 12!
Method 1: Install Node.js and NPM from Debian Repository
The easiest and best way is to install from the Debian repository. It might not give you the latest version, but it definitely gives you stability.
Step 1: Update the package list.
sudo apt update && sudo apt upgrade -y
Step 2: Install Node.js and NPM.
sudo apt install nodejs npm -y
Step 3: Verify installed versions.
node -v npm -v
Output:
Nodejs Version: v18.13.0 NPM Version: 9.2.0
Make sure that both Node.js and NPM are installed and running.
Method 2: Install Node.js and NPM from NodeSource
This method is for you only if you need the absolute latest version.
Step 1: Install required dependencies.
sudo apt install curl -y
Step 2: Download and install the NodeSource repository.
Replace 20.x with your preferred version.
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
Step 3: Install Node.js and NPM.
sudo apt install nodejs -y
Step 4: Verify Installation.
node -v npm -v
Output:
Nodejs Version: v20.10.0 NPM Version: 10.2.5
Method 3: Install Node.js using NVM, the Node Version Manager.
NVM is used to install and switch between different Node versions.
Step 1: Install NVM.
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Reload the shell configuration.
source ~/.bashrc
Step 2: Install Node.js.
Install the latest version.
nvm install --lts
To install a specific version, for example, 20.11.0.
nvm install 20.11.0
Step 3: Verify the installation.
node -v npm -v
Output:
Nodejs Version: v20.11.0 NPM Version: 10.2.5
List installed versions.
nvm ls
Output:
v18.13.0
v20.11.0
default: v18.13.0
node: stable (-> v20.11.0) (default)
To switch between versions:
nvm use 20.11.0
Steps to Uninstall Node.js and NPM on Debian 12
Uninstall Node.js Installed via APT
sudo apt remove nodejs npm -y sudo apt autoremove -y
Uninstall Node.js Installed via NodeSource
sudo apt remove nodejs -y sudo rm -rf /etc/apt/sources.list.d/nodesource.list
Uninstall Node.js Installed via NVM
First, remove the installed Node.js version.
nvm uninstall node
Then, remove NVM.
rm -rf ~/.nvm
Also remove any references to NVM in your shell configuration (~/.bashrc, ~/.bash_profile, or ~/.zshrc).
Conclusion
Installing Node.js and NPM on Debian 12 is simple and has a variety of installation methods to offer. Whether you want the stability of the Debian repository, the latest versions from NodeSource, or simply to have something to manage multiple versions: Each of those ways can give you an easy approach that suits your needs. With Node.js already installed, you can start developing and managing JavaScript applications seamlessly. Explore our guide on what is Node.js web server in detail.
FAQs
What is the best way to install Node.js on Debian 12?
The best way to install Node.js totally depends on your requirements:
- For stability: Use the Debian repository.
- For the latest features: Use NodeSource.
- To manage multiple versions: Use NVM
Know more about What is Node.js
How do I check the version of my Node.js and NPM?
You can check the version of Node.js and NPM with the following command,
node -v npm -v
Can I install multiple versions of Node.js on Debian 12?
Yes, using NVM, you can install and switch between multiple versions of Node.js on Debian 12.
How do I update Node.js and NPM?
To update Node.js using APT, run the following command,
sudo apt update && sudo apt upgrade -y
If using NodeSource, use:
sudo apt install --only-upgrade nodejs
If using NVM, use:
nvm install node
Detailed instructions on how to set up Node.js with NPM on Debian 11