...
Skip to main content
Print

How to Install Node.js on Ubuntu

You install the latest LTS version of Node.js on Ubuntu via the NodeSource repository. With PM2 you then keep your application online at all times, even after a server reboot. The Node.js version in the default Ubuntu repository is often outdated. Via NodeSource you get a current LTS version with updates.

Step 1: install Node.js

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

Step 2: check the version

node -v
npm -v

Step 3: keep your app online with PM2

PM2 starts your application in the background and restarts it automatically after a crash or reboot:

npm install -g pm2
pm2 start app.js --name mijnapp
pm2 startup
pm2 save
pm2XITENS
pm2 listshows all running applications.
pm2 logs mijnappshows the log files.
pm2 restart mijnapprestarts the application.

Step 4: make your app reachable via your domain

Let Nginx forward the traffic of your domain to the port of your app as a reverse proxy. Read how to install Nginx and add this line in the server block:

location / {
    proxy_pass http://127.0.0.1:3000;
}

Related articles

Table of Contents