Install Node & NPM on Linux (Debian/Ubuntu, Arch, NixOS, Void - APT, Pacman, NVM)

Install Node & NPM on Linux (Debian/Ubuntu, Arch, NixOS, Void - APT, Pacman, NVM)

Easierdocs Node.js Install Article Image

Debian/Ubuntu

Using apt repository:

sudo apt update
sudo apt install nodejs npm

Using NodeSource repository (recommended for latest versions):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

Arch Linux

sudo pacman -Sy nodejs npm

NixOs

nix-shell -p nodejs

or system wide with:

/etc/nixos/configuration.nix
environment.systemPackages = [
    pkgs.nodejs
];

Void Linux

sudo xbps-install -S nodejs

Generic Linux Distros

Step 1 - Download Node.js

Download the latest LTS version from the official Node.js site.

Step 2 - Remove any previous Node.js installation

sudo rm -rf /usr/local/nodejs

Step 3 - Extract downloaded Node.js files

tar -C /usr/local -xzf node-v20.12.2-linux-x64.tar.gz
ℹ️
Change the file name according to the current version you downloaded.

Step 4 - Add Node.js to PATH

Add /usr/local/nodejs/bin to the PATH environment variable:

echo 'export PATH=$PATH:/usr/local/nodejs/bin' >> $HOME/.profile
source $HOME/.profile

Step 5 - Verify the installation

node --version
npm --version

If these commands output the current versions, the installation was successful.

Alternative: Using NVM (Node Version Manager)

NVM allows you to install and manage multiple Node.js versions:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source $HOME/.bashrc
nvm install --lts
nvm use --lts

This is the recommended approach for developers who need to work with different Node.js versions.

Last updated on