How to Install Node.js and NPM on Debian 12?
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 you wish to go through installation methods for Node.js and NPM, this guide shall help you through installation using the default repositories, NodeSource, or other methods using 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.
Comprehensive Guide to Install Node.js & NPM on Debian 12
Let’s have a quick glance at a few steps to install Node.js & NPM on Debian 12!
Method 1: Install Node.js & 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
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 18.x with your preferred version.
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Step 3: Install Node.js and NPM.
sudo apt install nodejs -y
Step 4: Verify Installation.
node -v npm -v
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.3/install.sh | bash
Reload the shell configuration.
source ~/.bashrc
Step 2: Install Node.js.
Install the latest version.
nvm install node
To install a specific version, for example, 18.16.0.
nvm install node
Step 3: Verify the installation.
node -v npm -v
List installed versions.
nvm list
To switch between versions:
nvm use 18.16.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.
Frequently Asked Questions
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
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