Node.js is an open source Javascript runtime environment used in the development of web applications and network tools. It is built on the version 8 of Google Javascript Engine. It works on many platforms including Windows OS, Linux and Mac OS. This guide will cover installation of Node.js in Linux Mint 20.

With Node.js, you can use javascript as a server-side scripting language to create dynamic content for web pages.

How To Install Node.js in Linux Mint 20

Node.Js can be installed using three different methods:

  • Install Node.Js using NodeSource – NodeSource repository is set up in the Linux system to be used in installing Node.js
  • Install Node.Js using NVM (Node Version Manager) – NVM is a Node.Js version manager which is used in installing and managing Node.js and enables switching between varying node versions.
  • Install Node.Js using Ubuntu Repository – Node.js is installed from Ubuntu repository using the apt command

How To Install Node.js in Linux Mint 20 Using NodeSource

Here, we are going to install Node.js using NodeSource

Before installing Node.js in Linux Mint 20, ensure that your Linux repository index is updated using the below command

sudo apt-get update

Install Curl and Build-essential

Curl is used for downloading official Node.js installation script while build-essential is for compiling and installing native addons

sudo apt install curl build-essential

Add Nodesource Repository.

Run the command below to set up Nodesource repository in your system selecting what matches the Node.js version you want to install.

--- Node.js 14 ---
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

--- Node.js 13 ---
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -

--- Node.js 12 ---
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

--- Node.js 10 ---
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

Install Node.js on Linux Mint

After adding NodeSource repository, it is time to install Node.js. The command will also install NPM (Node Package Manager) which is a Javascript package manager.

sudo apt install -y nodejs

A successful installation will give the below output

Check Node.Js Version

Check Node.js version to verify installation

$ node -v

Output

Install Yarn Package Manager on Linux Mint

Yarn Package Manager is an alternative of NPM (Node Package Manager) which presents higher operation speeds with improved security and reliability.

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install -y yarn

Run Your Web Server with Node.js

It is now time to run our first web server with Node.js

Create a file called test.js

sudo nano test.js

Paste the below content in test.js. After pasting, press ctrl+ x, followed by y then Enter to save.

const http = require('http');
const port = 8080;
const server = http.createServer((req, res) => {
   res.writeHead(200, {'Content-Type': 'text/plain'});
   res.end('Hello World!\n');
});
server.listen(port, () => {
  console.log(`Node.js server listening on port ${port}`);
});

Start the Webserver with Node.js

The command below is used to start the Node.js web server running on port 8080

node --inspect test.js

A successful installation outputs the below content showing the web server running on the specified port, 8080.

Verifying Node.js Installation

On your browser, type http://localhost:8080

If the installation is successful, you will get your web page with the words ‘Hello World!’

This has been a step-by-step guide on how to install Node.js in Linux Mint 20 using NodeSource. Check more elaborate guides for your day-to-day Linux mint installations on our site.

Install Google Chrome Browser on Linux Mint

How To Install LAMP Stack on Linux Mint

How To Install Wine 5 on Linux Mint

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

2 × 4 =