How to install Node.js & Npm on Amazon ec2 Ubuntu Linux

Node.js is a V8 JavaScript runtime user interface and agile JavaScript interpreter.  In few words -Node.js is a method of running JavaScript on the webserver; but it is also much, much more. JavaScript is an event-based language, so anything that happens on the web server triggers a non-blocking opportunity. Here we learn how to install Node.js and NPM on Amazon  Ec2 running Ubuntu 20.04 Linux cloud server instance.

Even Node.js can take over the function of the web server – Apache – and translates the application code executed on it. Similar to Apache, there are various components (collections) that can be set up to include features as well as performance – such as information storage, zip data support, Facebook login, or payment gateways.

In a normal LAMP server stack, you have an underlying Apache or NGINX internet server running PHP. Each new link to the server creates a new string, and it’s extremely easy to quickly lose efficiency- the only way to support even more users is to add more web servers resources. It just doesn’t scale well. In the case of Node, this is not the instance. There is no Apache paying attention to inbound links and returning HTTP status codes as well – you have to handle this core server style yourself. The good news is that there are components that make this easy, but it can still be a little frustrating when you get started. However, the result is a powerful internet application.

Install node js on Amazon Ec2 Ubuntu Linux

1. Connect to your Ubuntu Instance

First of all, you should have an Ubuntu running Ec2 Instance on your Amazon Cloud infrastructure. If you already have a running Instance then move to the next step. Otherwise, check out how to create Ec2 Instance.

After that connect your Ubuntu Instance using SSH or via web terminal directly from the AWS Ec2 Dashboard.

 

2. Run system update

Once you have your Ec2 Ubuntu command line access run the system update command to ensure all the existing packages are up to date.

sudo apt update

Also, install curl:

sudo apt install curl -y

 

3. Check available Node.js Version

Node.js & NPM can be installed using the stable Ubuntu’s default system repository, however, the version will be old. To check that, you can run:

sudo apt policy nodejs

Output:

nodejs:
Installed: (none)
Candidate: 10.19.0~dfsg-3ubuntu1
Version table:
10.19.0~dfsg-3ubuntu1 500
500 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 Packages

 

4.  Add Nodejs current or LTS repo on Ec2 Ubuntu

Now, as we know already the version already available to install from the base Ubuntu repository is not the latest one. Therefore, to get the one, we need to add the official Node.JS repo manually to our system.

As per your requirement add one of the following repositories using the below-given commands:

For LTS version 

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

For Current Version

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -

 

5. Command to Install Nodejs & NPM on Amazon ec2 Ubuntu Linux

We already have the things in place, now we just need to download and install the current or LTS version of this Javascript platform.

Just run:

sudo apt-get install nodejs

 

6.  See the installed version

Once the installation is completed, you can check what are the versions of Node and NPM – (Nodejs package manager) installed on your system.

node -v
npm -v

In this way, we can easily get the Nodejs on an Ubuntu Instance running on Amazon Ec2. However, if you are facing any problems while going through the above steps, let’s know the command section is all yours…

 

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.