Installing Node.js in Debian 9
How to install Node.js via PPA or NVM on Debian 9.
Node.js is a runtime platform that brings JavaScript beyond the browser, turning it into a general-purpose language. It's widely used as a web server and also supports desktop app development via NW.js, AppJS, or Electron.
Update the package list and install curl:
sudo apt update
sudo apt install curl
Method 1. Installing via PPA
NodeSource maintains a Personal Package Archive (PPA) with up-to-date Node.js releases. Navigate to your home directory and download the setup script for the version you need:
cd ~
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
Review the script before running it:
nano nodesource_setup.sh
Run the script:
sudo bash nodesource_setup.sh
Once the PPA is added, install Node.js:
sudo apt install nodejs
Check the version:
nodejs -v
Expected output:
v10.20.1
The nodejs package already includes npm — no separate installation needed. Verify npm is available:
npm -v
6.14.4
To compile native packages, install build-essential:
sudo apt install build-essential
Method 2. Installing via NVM
NVM (Node Version Manager) lets you install and switch between multiple Node.js versions on the same machine — ideal when different projects need different runtimes.
Download the installation script:
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh -o install_nvm.sh
Review the script before running it:
nano install_nvm.sh
Run the installer:
bash install_nvm.sh
Load NVM into the current session:
source ~/.profile
Browse available Node.js versions:
nvm ls-remote
Install a specific version — for example, v12.16.3:
nvm install v12.16.3
Switch to it:
nvm use v12.16.3
Confirm the active version:
node -v
v12.16.3
List all installed versions:
nvm ls
Set a default version:
nvm alias default 10.20.1
This version will be used every time you open a new terminal session. You can also switch to it explicitly:
nvm use default
Managing packages with npm
Each Node.js version manages its own packages independently.
Install a package locally:
npm install express
Install a package globally (available to all projects using the same Node.js version):
npm install -g express
Link a globally installed package to a local project:
npm link express
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!