install nodejs ubuntu apt code example

Example 1: install node js ubuntu

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install nodejs
# Check node version
node -v 
# v13.9.0
# Also, check the npm version
npm -v 
# 6.13.7

Example 2: ubuntu install node js

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt install nodejs
sudo apt install npm
sudo apt update

Example 3: install node js lts ubuntu 18.04

// Enabling NodeSource Repository
// replace %V% with desired major version
curl -sL https://deb.nodesource.com/setup_%V%.x | sudo bash -
// Install using apt-get
sudo apt-get install -y nodejs
// check installed node version
node --version

Example 4: how to install npm and node js ubuntu

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -
sudo apt-get install nodejs
# Check node version
node -v 
# v15.14.0
# Also, check the npm version
npm -v 
# 7.7.6

Example 5: ubuntu install latest node and npm

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

# Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
apt-get install -y nodejs