---
title: "How to Install and Configure Node.js on EC2 Instance Amazon Linux 2"
description: "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."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/blog/post/how-to-install-and-configure-nodejs-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.

```shell
# 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:

```shell
# 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:

```shell
# 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:

```shell
node -v
```

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

```shell
# 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

- [Node.js Official Website](https://nodejs.org/)
- [NodeSource Node.js Binary Distributions](https://github.com/nodesource/distributions)
- [Installing Node.js via package manager - NodeSource](https://nodejs.org/en/download/package-manager/#enterprise-linux-and-fedora)
- [Amazon EC2 User Guide for Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html)
- [Amazon Linux 2 AMI FAQs](https://aws.amazon.com/amazon-linux-2/faqs/)
- [Connect to your Linux instance using SSH](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html)
- [Managing software on your Linux instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-software.html)
- [Red Hat Enterprise Linux (RHEL) and CentOS `yum` command cheat sheet](https://access.redhat.com/sites/default/files/attachments/rh_yum_cheatsheet_1214_jcs_print-1.pdf) (Amazon Linux is RHEL-based)
- [cURL Manual](https://curl.se/docs/manual.html)
- [Bash Manual](https://www.gnu.org/software/bash/manual/bash.html)
