How to Install Node.js and npm on Debian 10 Linux
4 min read
npm is the default package manager for Node.js that helps developers to share and reuse their code.
In this tutorial, we will show you several different ways of installing Node.js and npm on Debian 10 Buster. Choose the installation option that is appropriate for your environment.
Installing Node.js and npm from the Debian repositories
Node.js and npm can be installed from the standard Debian repositories. At the time of writing, the version in the repositories is v10.x which is the latest LTS version.
To install Node.js and npm on your Debian use the following commands:
sudo apt update
sudo apt install nodejs npm
One the installation is completed, verify it by typing:
The command will display the Node.js version:
This is the easiest way to install Node.js and npm on Debian and should be sufficient for most use cases.
Installing Node.js and npm from the NodeSource repository
NodeSource is a company focused on providing enterprise-grade Node support. It maintains an APT repository containing multiple Node.js versions.
Use this repository if you need to install a specific version of Node.js. At the time of writing, NodeSource repository provides the following versions:
- v12.x - The latest stable version.
- v10.x - The latest LTS version.
- v8.x - The previous LTS version.
We’ll install Node.js version 12.x.
Start by adding add the NodeSource repository to your system by running the following
curl -sL https://deb.nodesource.com/setup_12.x | sudo bash -
Once the repository is added to install Node.js and npm type:
sudo apt install nodejs
Ensure that Node.js is properly installed by typing:
Installing Node.js and npm using NVM
NVM (Node Version Manager) is a bash script that allows you to manage multiple Node.js versions. With NVM you can install and uninstall any Node.js version that you want to use or test.
Use this method if you want to install Node.js on a per-user basis.
To install NVM on your system type the command below. Do not use
sudo as it will enable the script for the root user.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
The installation script clones the
nvm repository from Github to the
~/.nvm directory and adds the nvm path to your Bash or ZSH profile.
... export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
To start using the nvm script either open a new shell session or run the commands printed on your screen. Do whatever is easier for you.
Now that the
nvm script is installed on your Debian system, you can install the latest stable version of Node.js with:
nvm install node
... Computing checksum with sha256sum Checksums matched! Now using node v12.8.1 (npm v6.10.2) Creating default alias: default -> node (-> v12.8.1)
Let’s install two more versions, the latest LTS version and version 8.16.0:
nvm install --lts
nvm install 8.16.0
Once done, to list all installed Node.js versions type:
-> v8.16.0 v10.16.2 v12.8.1 default -> node (-> v12.8.1) node -> stable (-> v12.8.1) (default) stable -> 12.8 (-> v12.8.1) (default) iojs -> N/A (default) unstable -> N/A (default) lts/* -> lts/dubnium (-> v10.16.2) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.16.0 lts/dubnium -> v10.16.2
The entry with an arrow on the right
(-> v8.16.0), is the version used in the current shell session and the default version is set to
v12.8.1. The default version is the version that will be used when you open new shell sessions.
If you want to change the currently active version, let’s say to v10.16.2 you would run:
nvm use 8.11.3
To change the default Node.js, for example to
nvm alias default 8.11.3
Installing Development Tools
The development tools are necessary for compiling and installing native add-ons from the npm registry. Install the package by running:
sudo apt install build-essential
If for some reasons you want to uninstall Node.js and npm packages, use the following command:
sudo apt remove nodejs npm
We have shown you three different ways to install Node.js and npm on your Debian 10 system. The method you choose depends on your requirements and preferences.
Now that you’ve installed Node.js on your Debian 10 system, it’s time to deploy your application.
If you have any questions or feedback, feel free to comment below.