---
title: "How to Install and Configure Node.js on EC2 Instance Amazon Linux 2"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2
---

![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.](/_astro/hero.CIYv_zEL_DsM4T.webp)

[Home](/)›[Blog](/blog)›[All Categories](/blog/categories)›[AWS](/blog/categories/aws)

Blog

[Prev in AWSHow to Deploy a Spring Boot Application to AWS CloudFormation](/blog/post/how-to-deploy-a-spring-boot-application-to-aws-cloudformation)[Next in AWSHow to Install and Setup FireWall on Amazon Linux 2](/blog/post/how-to-install-and-setup-firewall-on-amazon-linux-2)

[AWS](/blog/categories/aws)[EC2](/blog/categories/ec2)[Node.js](/blog/categories/nodejs)[Linux](/blog/categories/linux)

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

[Mohammad Abu Mattar](/authors/mohammad-abu-mattar)Published: 07 Nov 202202 Mins read02 Mins listen

[Markdown for AI(opens in a new tab)](/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

TL;DR

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.

Series

[AWS Automation](/series/aws-automation)3/6

[PreviousHow to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)[NextHow to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)

All posts in this series (6)

Blog6

1.  [How to Run an Apache Web Server Using Docker on an AWS EC2 Instance](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)
2.  [How to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)
3.  [How to Install and Configure Node.js on EC2 Instance Amazon Linux 2You are here](/blog/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2)
4.  [How to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)
5.  [How To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUI](/blog/post/how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui)
6.  [Scaling Up, Staying Strong: Hands-On AWS CloudFormation Techniques for Building Resilient and Scalable Systems](/blog/post/scaling-up-staying-strong-hands-on-aws-cloudformation-techniques-for-building-resilient-and-scalable-systems)

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

Contents

[Introduction](#introduction)[Prerequisites](#prerequisites)[Step 1: update the system packages and install the dependency packages](#step-1-update-the-system-packages-and-install-the-dependency-packages)[Step 2: add the Node.js repository](#step-2-add-the-nodejs-repository)[Step 3: install Node.js](#step-3-install-nodejs)[Step 4: check the Node.js version](#step-4-check-the-nodejs-version)[Conclusion](#conclusion)[References](#references)

## [Introduction](#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](#prerequisites)

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

## [Step 1: update the system packages and install the dependency packages](#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

```
1# Update the system packages2sudo yum update -y3
4# Install dependencies packages5sudo yum install gcc-c++ make -y
```

## [Step 2: add the Node.js repository](#step-2-add-the-nodejs-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

```
1# Install Node.js repository 14.x2curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -3
4# Install Node.js repository 16.x5curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -6
7# Install Node.js repository 17.x8curl -sL https://rpm.nodesource.com/setup_17.x | sudo bash -9
10# Install Node.js repository 18.x11curl -sL https://rpm.nodesource.com/setup_18.x | sudo bash -
```

## [Step 3: install Node.js](#step-3-install-nodejs)

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

```
1# update the system2sudo yum update -y3
4# Install Node.js5sudo yum install nodejs -y
```

## [Step 4: check the Node.js version](#step-4-check-the-nodejs-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

```
1node -v
```

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

Terminal window

```
1# Node.js 14.x2v14.18.13
4# Node.js 16.x5v16.13.06
7# Node.js 17.x8v17.0.19
10# Node.js 18.x11v18.0.0
```

## [Conclusion](#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](#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)

Was this useful?

## Tags

[#Node.js Installation](/blog/tags/nodejs-installation)[#Amazon Linux 2](/blog/tags/amazon-linux-2)[#AWS EC2 Setup](/blog/tags/aws-ec2-setup)[#NodeSource](/blog/tags/nodesource)[#Server Setup](/blog/tags/server-setup)[#JavaScript Runtime](/blog/tags/javascript-runtime)

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2 "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=How%20to%20Install%20and%20Configure%20Node.js%20on%20EC2%20Instance%20Amazon%20Linux%202&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2 "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2&title=How%20to%20Install%20and%20Configure%20Node.js%20on%20EC2%20Instance%20Amazon%20Linux%202&summary=Node.js%20does%20not%20exist%20in%20the%20default%20Amazon%20Linux%202%20repository.%20So%2C%20we%20need%20to%20add%20the%20Node.js%20repository%20to%20the%20system.%20In%20this%20post%2C%20we%20will%20learn%20how%20to%20install%20and%20configure%20Node.js%20on%20EC2%20Instance%20Amazon%20Linux%202.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=How%20to%20Install%20and%20Configure%20Node.js%20on%20EC2%20Instance%20Amazon%20Linux%202%20https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2 "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2&text=How%20to%20Install%20and%20Configure%20Node.js%20on%20EC2%20Instance%20Amazon%20Linux%202 "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2&title=How%20to%20Install%20and%20Configure%20Node.js%20on%20EC2%20Instance%20Amazon%20Linux%202 "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2&t=How%20to%20Install%20and%20Configure%20Node.js%20on%20EC2%20Instance%20Amazon%20Linux%202 "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2&media=&description=Node.js%20does%20not%20exist%20in%20the%20default%20Amazon%20Linux%202%20repository.%20So%2C%20we%20need%20to%20add%20the%20Node.js%20repository%20to%20the%20system.%20In%20this%20post%2C%20we%20will%20learn%20how%20to%20install%20and%20configure%20Node.js%20on%20EC2%20Instance%20Amazon%20Linux%202. "Share on Pinterest")[Email](<mailto:?subject=How%20to%20Install%20and%20Configure%20Node.js%20on%20EC2%20Instance%20Amazon%20Linux%202&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2>)

## Comments

## You might also enjoy

More posts on similar topics

[![How to Run an Apache Web Server Using Docker on an AWS EC2 Instance](/_astro/hero.WA3H4xsW_KuMrf.webp)](/blog/post/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](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [Docker](/blog/categories/docker)
-   [Apache](/blog/categories/apache)
-   [Web Server](/blog/categories/web-server)

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\](

[#AWS EC2 Docker](/blog/tags/aws-ec2-docker)[#Apache Docker](/blog/tags/apache-docker)[#Containerization](/blog/tags/containerization)+4 tags

[read more](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)

[![How to Connect to AWS RDS MySQL Database to EC2 Instance With PHP By Using PDO](/_astro/hero.BbyjrsxP_xhG8d.webp)](/blog/post/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](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [RDS](/blog/categories/rds)
-   [EC2](/blog/categories/ec2)
-   [PHP](/blog/categories/php)
-   [MySQL](/blog/categories/mysql)
-   [Database](/blog/categories/database)

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

[#AWS RDS MySQL](/blog/tags/aws-rds-mysql)[#EC2 PHP PDO](/blog/tags/ec2-php-pdo)[#Database Connection](/blog/tags/database-connection)+5 tags

[read more](/blog/post/how-to-connect-to-aws-rds-mysql-database-to-ec2-instance-with-php-by-using-pdo)

[![How To Connect A EBS Volume To An Windows EC2 Instance Using Powershell/GUI](/_astro/hero.CPGBv147_1yKKK8.webp)](/blog/post/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](/blog/post/how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [Windows Server](/blog/categories/windows-server)
-   [EC2](/blog/categories/ec2)
-   [EBS](/blog/categories/ebs)
-   [PowerShell](/blog/categories/powershell)

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

[#AWS EBS](/blog/tags/aws-ebs)[#Windows EC2](/blog/tags/windows-ec2)[#Attach EBS Volume](/blog/tags/attach-ebs-volume)+5 tags

[read more](/blog/post/how-to-connect-a-ebs-volume-to-an-windows-ec2-instance-using-powershell-gui)

[![How to Create a AWS RDS MySQL Database and Connect to it using MySQL Workbench](/_astro/hero.BalpSU3D_jRzSY.webp)](/blog/post/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](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [RDS](/blog/categories/rds)
-   [MySQL](/blog/categories/mysql)
-   [Database Management](/blog/categories/database-management)
-   [Cloud Computing](/blog/categories/cloud-computing)

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

[#AWS RDS Setup](/blog/tags/aws-rds-setup)[#MySQL Workbench Connection](/blog/tags/mysql-workbench-connection)[#Relational Database](/blog/tags/relational-database)+4 tags

[read more](/blog/post/how-to-create-a-aws-rds-mysql-database-and-connect-to-it-using-mysql-workbench)

[![How to Install PHP and MariaDB on Amazon Linux 2](/_astro/hero.BxVn8-Uf_Z1fCiGj.webp)](/blog/post/how-to-install-php-and-mariadb-on-amazon-linux-2)

## [How to Install PHP and MariaDB on Amazon Linux 2](/blog/post/how-to-install-php-and-mariadb-on-amazon-linux-2)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [PHP](/blog/categories/php)
-   [MariaDB](/blog/categories/mariadb)
-   [Apache](/blog/categories/apache)
-   [LAMP Stack](/blog/categories/lamp-stack)
-   [Linux](/blog/categories/linux)

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

[#PHP Installation](/blog/tags/php-installation)[#MariaDB Installation](/blog/tags/mariadb-installation)[#Amazon Linux 2](/blog/tags/amazon-linux-2)+5 tags

[read more](/blog/post/how-to-install-php-and-mariadb-on-amazon-linux-2)

[![How to Install and Setup FireWall on Amazon Linux 2](/_astro/hero.b8oDtFR4_ZdWcUP.webp)](/blog/post/how-to-install-and-setup-firewall-on-amazon-linux-2)

## [How to Install and Setup FireWall on Amazon Linux 2](/blog/post/how-to-install-and-setup-firewall-on-amazon-linux-2)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [Linux](/blog/categories/linux)
-   [Firewall](/blog/categories/firewall)
-   [Security](/blog/categories/security)

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

[#Firewalld](/blog/tags/firewalld)[#Amazon Linux 2](/blog/tags/amazon-linux-2)[#EC2 Security](/blog/tags/ec2-security)+5 tags

[read more](/blog/post/how-to-install-and-setup-firewall-on-amazon-linux-2)

6 related posts
