Blog post image for How to Install and Configure Node.js on EC2 Instance Amazon Linux 2 - Node.js does not exist in the default Amazon Linux 2 repository. So, we need to add the Node.js repository to the system. In this post, we will learn how to install and configure Node.js on EC2 Instance Amazon Linux 2.
Blog

How to Install and Configure Node.js on EC2 Instance Amazon Linux 2

Published: 02 Mins read02 Mins listen

Introduction

Node.js does not exist in the default Amazon Linux 2 repository. So, we need to add the Node.js repository to the system. In this post, we will learn how to install and configure Node.js on EC2 Instance Amazon Linux 2.

Prerequisites

  • AWS Account
  • EC2 Instance Amazon Linux 2
  • SSH Client

Step 1: Update the System Packages and Install Dependencies Packages

First, we need to update the system packages and install dependencies packages.

Terminal window
# Update the system packages
sudo yum update -y
# Install dependencies packages
sudo yum install gcc-c++ make -y

Step 2: Install Node.js

First, we need to install Node.js on our EC2 Instance. To do that, we need to add the Node.js repository to the system. To add the Node.js repository, we need to run the following command:

Terminal window
# Install Node.js repository 14.x
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
# Install Node.js repository 16.x
curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
# Install Node.js repository 17.x
curl -sL https://rpm.nodesource.com/setup_17.x | sudo bash -
# Install Node.js repository 18.x
curl -sL https://rpm.nodesource.com/setup_18.x | sudo bash -

Step 3: Install Node.js

After choosing the Node.js version, we need to install Node.js on our EC2 Instance. To do that, we need to run the following command:

Terminal window
# update the system
sudo yum update -y
# Install Node.js
sudo yum install nodejs -y

Step 4: Check Node.js Version

After installing Node.js, we need to check the Node.js version. To do that, we need to run the following command:

Terminal window
node -v

Output depends on the Node.js version that you choose.

Terminal window
# Node.js 14.x
v14.18.1
# Node.js 16.x
v16.13.0
# Node.js 17.x
v17.0.1
# Node.js 18.x
v18.0.0

Conclusion

In this post, we learned how to install and configure Node.js on EC2 Instance Amazon Linux 2. We learned how to add the Node.js repository to the system and install Node.js on our EC2 Instance.

References

Related Posts

You might also enjoy

Check out some of our other posts on similar topics

How to Run an Apache Web Server Using Docker on an AWS EC2 Instance

How to Run an Apache Web Server Using Docker on an AWS EC2 Instance

Introduction In this post, we will learn how to run an Apache web server using Docker on an AWS EC2 instance. We will use the following tools:AWS EC2 [Docker](

How to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO

How to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO

Introduction In this post, we will learn how to connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO. PrerequisitesAWS Account EC2 Instance Amazon Linux 2 RDS MySQL

How To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUI

How To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUI

Introduction In this post, we will learn how to connect a EBS volume to an Windows EC2 instance using Powershell/GUI and also how to mount the EBS volume to the EC2 instance. Prerequisites

How to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench

How to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench

Introduction RDS is a managed service that makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-c

How to Install PHP and MariaDB on Amazon Linux 2

How to Install PHP and MariaDB on Amazon Linux 2

Introduction We will learn how to set up PHP and MariaDB on Amazon Linux 2 in this tutorial. We will also discover how to set up PHP so that it functions with the Apache web server. We will also d

How to Install and Setup FireWall on Amazon Linux 2

How to Install and Setup FireWall on Amazon Linux 2

Introduction We will learn how to install and setup FireWall on Amazon Linux 2 in this tutorial. We will also discover how to set up FireWall so that it functions with the Amazon Linux 2. Prer

6 related posts