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

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

Check out some of our other posts

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

How to Install WordPress on Amazon Linux 2

How to Install WordPress on Amazon Linux 2

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

How to Install Apache Web Server on Amazon Linux 2

How to Install Apache Web Server on Amazon Linux 2

Introduction In this tutorial, we will learn how to install Apache web server on Amazon Linux 2. We will also learn how to configure Apache web server to run simple HTML web page. Prerequisite

How To Create An AWS EC2 Instance Using AWS CLI

How To Create An AWS EC2 Instance Using AWS CLI

Introduction We will learn how to create an AWS EC2 instance using AWS CLI in this tutorial. We will also discover how to set up an AWS EC2 instance so that it functions with the Apache web server

How to Install Jenkins on AWS EC2 Instance

How to Install Jenkins on AWS EC2 Instance

Introduction In this post, I will show you how to Create an EC2 Instance on AWS and install Jenkins on it. PrerequisitesAWS CLI installed and configured IAM user with the following permi