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)
Debian/Ubuntu
Using apt repository:
sudo apt update
sudo apt install nodejs npmUsing NodeSource repository (recommended for latest versions):
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejsArch Linux
sudo pacman -Sy nodejs npmNixOs
nix-shell -p nodejsor system wide with:
/etc/nixos/configuration.nix
environment.systemPackages = [
pkgs.nodejs
];Void Linux
sudo xbps-install -S nodejsGeneric 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/nodejsStep 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/.profileStep 5 - Verify the installation
node --version
npm --versionIf 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 --ltsThis is the recommended approach for developers who need to work with different Node.js versions.
Last updated on