Installing Node.js on Ubuntu 18.04
How to install Node.js from the default repositories, via PPA, or via NVM on Ubuntu 18.04.
Node.js is a runtime platform that takes JavaScript well 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 before getting started:
sudo apt update
Method 1. Installing from the default repositories
The quickest option — though the version in Ubuntu's repositories may be outdated.
sudo apt install nodejs
sudo apt install npm
On Ubuntu, the executable is called
nodejsinstead ofnodedue to a naming conflict with another package.
Check the version:
nodejs -v
v8.10.0
Method 2. Installing via PPA
NodeSource maintains a PPA with up-to-date Node.js releases. Navigate to your home directory and download the setup script for the version you need (replace 10.x with your target version):
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
Install Node.js:
sudo apt install nodejs
Check the version:
nodejs -v
v10.20.1
The nodejs package already includes npm — no separate installation needed:
npm -v
6.14.4
To compile packages from source, install build-essential:
sudo apt install build-essential
Method 3. 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
NVM installs to ~/.nvm and adds the necessary configuration to ~/.profile. Load NVM into the current session:
source ~/.profile
Browse available Node.js versions:
nvm ls-remote
Install the version you need — for example, 10.20.1:
nvm install 10.20.1
Switch to it:
nvm use 10.20.1
When installed via NVM, the executable is called node. Confirm the active version:
node -v
v10.20.1
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
Each Node.js version manages its own packages independently via npm.
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!