How To Install Node.js on Linux Mint 21

0
887
How To Install Node.js on Linux Mint 21
How To Install Node.js on Linux Mint 21

This guide will take you through how to install Node.js on Linux Mint 21. Node.js is a back-end JavaScript runtime environment that is open-source, cross-platform, runs on the V8 engine, and executes JavaScript code outside of a web browser. It was created to help create scalable network applications.

Table of Contents

- Advertisement -

Update Linux Mint

Update Linux mint by running the command below on your terminal.

sudo apt update

Then install curl and build essential using the following command.

sudo apt install curl build-essential

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
curl is already the newest version (7.81.0-1ubuntu1.3).
The following additional packages will be installed:
  g++ g++-11 libc-dev-bin libc-devtools libc6-dev libcrypt-dev libnsl-dev
  libstdc++-11-dev libtirpc-dev rpcsvc-proto
Suggested packages:
  g++-multilib g++-11-multilib gcc-11-doc glibc-doc libstdc++-11-doc
The following NEW packages will be installed:
  build-essential g++ g++-11 libc-dev-bin libc-devtools libc6-dev libcrypt-dev
  libnsl-dev libstdc++-11-dev libtirpc-dev rpcsvc-proto
0 upgraded, 11 newly installed, 0 to remove and 211 not upgraded.
Need to get 16.1 MB of archives.
After this operation, 64.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libc-dev-bin amd64 2.35-0ubuntu3 [20.3 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 libcrypt-dev amd64 1:4.4.27-1 [112 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/main amd64 rpcsvc-proto amd64 1.4.2-0ubuntu6 [68.5 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy/main amd64 libtirpc-dev amd64 1.3.2-2build1 [192 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 libnsl-dev amd64 1.3.0-2build2 [71.3 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/main amd64 libc6-dev amd64 2.35-0ubuntu3 [2,099 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/main amd64 libstdc++-11-dev amd64 11.2.0-19ubuntu1 [2,083 kB]
Get:8 http://archive.ubuntu.com/ubuntu jammy/main amd64 g++-11 amd64 11.2.0-19ubuntu1 [11.4 MB]
Get:9 http://archive.ubuntu.com/ubuntu jammy/main amd64 g++ amd64 4:11.2.0-1ubuntu1 [1,412 B]
Get:10 http://archive.ubuntu.com/ubuntu jammy/main amd64 build-essential amd64 12.9ubuntu3 [4,744 B]
Get:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 libc-devtools amd64 2.35-0ubuntu3 [28.9 kB]
Fetched 16.1 MB in 2min 8s (126 kB/s)                                          
Selecting previously unselected package libc-dev-bin.
(Reading database ... 282000 files and directories currently installed.)
Preparing to unpack .../00-libc-dev-bin_2.35-0ubuntu3_amd64.deb ...
Unpacking libc-dev-bin (2.35-0ubuntu3) ...
Selecting previously unselected package libcrypt-dev:amd64.
Preparing to unpack .../01-libcrypt-dev_1%3a4.4.27-1_amd64.deb ...
Unpacking libcrypt-dev:amd64 (1:4.4.27-1) ...
Selecting previously unselected package rpcsvc-proto.
Preparing to unpack .../02-rpcsvc-proto_1.4.2-0ubuntu6_amd64.deb ...
Unpacking rpcsvc-proto (1.4.2-0ubuntu6) ...

Install Node.Js using NodeSource Repository

Start by adding the NodeSource repository, use the following commands to add a specific version of Node.js that you want to use.

### Node.js 18 ###
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

### Node.js 16 ###
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

### Node.js 14 ###
curl -sL https://deb.nodesource.com/setup_14.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

Run the command below to install Node.js on Linux Mint 21.

sudo apt install -y nodejs

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  javascript-common libjs-highlight.js libnode72 nodejs-doc
Suggested packages:
  apache2 | lighttpd | httpd npm
The following NEW packages will be installed:
  javascript-common libjs-highlight.js libnode72 nodejs nodejs-doc
0 upgraded, 5 newly installed, 0 to remove and 211 not upgraded.
Need to get 13.7 MB of archives.
After this operation, 53.8 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 javascript-common all 11+nmu1 [5,936 B]
Get:2 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libjs-highlight.js all 9.18.5+dfsg1-1 [367 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libnode72 amd64 12.22.9~dfsg-1ubuntu3 [10.8 MB]
Get:4 http://archive.ubuntu.com/ubuntu jammy/universe amd64 nodejs-doc all 12.22.9~dfsg-1ubuntu3 [2,409 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy/universe amd64 nodejs amd64 12.22.9~dfsg-1ubuntu3 [122 kB]
Fetched 13.7 MB in 1min 21s (169 kB/s)                                         
Selecting previously unselected package javascript-common.
(Reading database ... 283559 files and directories currently installed.)
Preparing to unpack .../javascript-common_11+nmu1_all.deb ...
Unpacking javascript-common (11+nmu1) ...
Selecting previously unselected package libjs-highlight.js.
Preparing to unpack .../libjs-highlight.js_9.18.5+dfsg1-1_all.deb ...
Unpacking libjs-highlight.js (9.18.5+dfsg1-1) ...
Selecting previously unselected package libnode72:amd64.
Preparing to unpack .../libnode72_12.22.9~dfsg-1ubuntu3_amd64.deb ...
Unpacking libnode72:amd64 (12.22.9~dfsg-1ubuntu3) ...
Selecting previously unselected package nodejs-doc.
Preparing to unpack .../nodejs-doc_12.22.9~dfsg-1ubuntu3_all.deb ...
Unpacking nodejs-doc (12.22.9~dfsg-1ubuntu3) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_12.22.9~dfsg-1ubuntu3_amd64.deb ...
Unpacking nodejs (12.22.9~dfsg-1ubuntu3) ...
Setting up javascript-common (11+nmu1) ...
Setting up libnode72:amd64 (12.22.9~dfsg-1ubuntu3) ...
Setting up libjs-highlight.js (9.18.5+dfsg1-1) ...
Setting up nodejs (12.22.9~dfsg-1ubuntu3) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto m
ode
Setting up nodejs-doc (12.22.9~dfsg-1ubuntu3) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for doc-base (0.11.1) ...
Processing 1 added doc-base file...

Check the version of Node.js installed using the command below.

node -v

Install Yarn on Linux Mint

Yarn is a package manager like Node package manager(NPM), use the commands below to install it. Start by adding the GPG signing key.

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

Then add a repository containing yarn.

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Next, update your system to update repos.

sudo apt install -y yarn

Check the yarn version installed.

yarn -v

Create a sample Node.js web server

Create a sample file.

sudo nano sample.js

Then paste the sample code below.

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

Start Node.js server using the following command.

node sample.js

Access your app from your browser by entering http://localhost:3000

That marks the end of our article, Cheers!

Read more on Node.js Documentation

Other Tutorials

How to Install Htop on Rocky Linux 9| AlmaLinux 9| CentOS 9| RHEL 9

Install latest version of NodeJS on Ubuntu 22.04 LTS

Install PHP 8.1 on Rocky Linux 9

LEAVE A REPLY

Please enter your comment!
Please enter your name here