Sheet ⁨02⁩ · ⁨Blog⁩Surveyed ⁨2026⁩

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.

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

Published: 02 Mins read02 Mins listen
Markdown for AI(opens in a new tab)

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 the dependency packages

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

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

Step 2: add the Node.js repository

Node.js is not in the default repository, so before we can install it on our EC2 instance we need to add the Node.js repository to the system. Pick the version you want and run the matching 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 the 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

Was this useful?

You might also enjoy

More 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 an AWS RDS MySQL database to an EC2 instance with PHP, 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 an EBS volume to a Windows EC2 instance using PowerShell or the Disk Management GUI, and how to mount the volume on the instance. Prereq

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 In this tutorial we will set up PHP and MariaDB on Amazon Linux 2. We will get PHP working with the Apache web server, secure the MariaDB install, and then connect the two with a smal

How to Install and Setup FireWall on Amazon Linux 2

How to Install and Setup FireWall on Amazon Linux 2

Introduction This tutorial covers installing and configuring firewalld on Amazon Linux 2, including setting the default zone and managing services and ports. Prerequisites To follow along wit

6 related posts