Install nginx on Amazon Linux 2023

Eika Chiu
3 min readOct 29, 2023

I recently created an EC2 of Amazon Linux 2023, when I tried the command with `amazon-linux-extras`, the command was not recognized.

Well, this article is probably only applicable to Amazon Linux 2023 not the earlier version Amazon Linux 2, if you’re running Amazon Linux 2 you can refer to “Install nginx on to AWS EC2 / Lightsail Amazon Linux 2”.

Here is a simple solution. Use the dnf command instead.

dnf search nginx

Following is the the output when it executes.

[ec2-user@ip-172-26-11-167 ~]$ dnf search nginx
Amazon Linux 2023 repository 17 MB/s | 20 MB 00:01
Amazon Linux 2023 Kernel Livepatch repository 661 kB/s | 162 kB 00:00
google-chrome 18 kB/s | 3.6 kB 00:00
======================================= Name Exactly Matched: nginx ========================================
nginx.x86_64 : A high performance web server and reverse proxy server
====================================== Name & Summary Matched: nginx =======================================
collectd-nginx.x86_64 : Nginx plugin for collectd
nginx-all-modules.noarch : A meta package that installs all available Nginx modules
nginx-core.x86_64 : nginx minimal core
nginx-filesystem.noarch : The basic directory layout for the Nginx server
nginx-mimetypes.noarch : MIME type mappings for nginx
nginx-mod-devel.x86_64 : Nginx module development files
nginx-mod-http-image-filter.x86_64 : Nginx HTTP image filter module
nginx-mod-http-perl.x86_64 : Nginx HTTP perl module
nginx-mod-http-xslt-filter.x86_64 : Nginx XSLT module
nginx-mod-mail.x86_64 : Nginx mail modules
nginx-mod-stream.x86_64 : Nginx stream modules

Since we have found it. We can run the following dnf command to install it.

sudo dnf install nginx

Here is the output when it run successfully.

[ec2-user@ip-172-26-11-167 ~]$ sudo dnf install nginx
Last metadata expiration check: 21:11:59 ago on Sat Oct 28 05:37:19 2023.
Dependencies resolved.
============================================================================================================
Package Architecture Version Repository Size
============================================================================================================
Installing:
nginx x86_64 1:1.24.0-1.amzn2023.0.2 amazonlinux 32 k
Installing dependencies:
generic-logos-httpd noarch 18.0.0-12.amzn2023.0.3 amazonlinux 19 k
gperftools-libs x86_64 2.9.1-1.amzn2023.0.2 amazonlinux 309 k
libunwind x86_64 1.4.0-5.amzn2023.0.2 amazonlinux 66 k
nginx-core x86_64 1:1.24.0-1.amzn2023.0.2 amazonlinux 586 k
nginx-filesystem noarch 1:1.24.0-1.amzn2023.0.2 amazonlinux 9.1 k
nginx-mimetypes noarch 2.1.49-3.amzn2023.0.3 amazonlinux 21 k

Transaction Summary
============================================================================================================
Install 7 Packages

Total download size: 1.0 M
Installed size: 3.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): libunwind-1.4.0-5.amzn2023.0.2.x86_64.rpm 885 kB/s | 66 kB 00:00
(2/7): nginx-1.24.0-1.amzn2023.0.2.x86_64.rpm 976 kB/s | 32 kB 00:00
(3/7): gperftools-libs-2.9.1-1.amzn2023.0.2.x86_64.rpm 2.6 MB/s | 309 kB 00:00
(4/7): generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch.rpm 958 kB/s | 19 kB 00:00
(5/7): nginx-mimetypes-2.1.49-3.amzn2023.0.3.noarch.rpm 564 kB/s | 21 kB 00:00
(6/7): nginx-core-1.24.0-1.amzn2023.0.2.x86_64.rpm 3.4 MB/s | 586 kB 00:00
(7/7): nginx-filesystem-1.24.0-1.amzn2023.0.2.noarch.rpm 271 kB/s | 9.1 kB 00:00
------------------------------------------------------------------------------------------------------------
Total 4.1 MB/s | 1.0 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: nginx-filesystem-1:1.24.0-1.amzn2023.0.2.noarch 1/7
Installing : nginx-filesystem-1:1.24.0-1.amzn2023.0.2.noarch 1/7
Installing : nginx-mimetypes-2.1.49-3.amzn2023.0.3.noarch 2/7
Installing : generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch 3/7
Installing : libunwind-1.4.0-5.amzn2023.0.2.x86_64 4/7
Installing : gperftools-libs-2.9.1-1.amzn2023.0.2.x86_64 5/7
Installing : nginx-core-1:1.24.0-1.amzn2023.0.2.x86_64 6/7
Installing : nginx-1:1.24.0-1.amzn2023.0.2.x86_64 7/7
Running scriptlet: nginx-1:1.24.0-1.amzn2023.0.2.x86_64 7/7
Verifying : nginx-core-1:1.24.0-1.amzn2023.0.2.x86_64 1/7
Verifying : libunwind-1.4.0-5.amzn2023.0.2.x86_64 2/7
Verifying : gperftools-libs-2.9.1-1.amzn2023.0.2.x86_64 3/7
Verifying : nginx-1:1.24.0-1.amzn2023.0.2.x86_64 4/7
Verifying : nginx-mimetypes-2.1.49-3.amzn2023.0.3.noarch 5/7
Verifying : generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch 6/7
Verifying : nginx-filesystem-1:1.24.0-1.amzn2023.0.2.noarch 7/7
============================================================================================================
WARNING:
A newer release of "Amazon Linux" is available.

Available Versions:

Version 2023.2.20231018:
Run the following command to upgrade to 2023.2.20231018:

dnf upgrade --releasever=2023.2.20231018

Release notes:
https://docs.aws.amazon.com/linux/al2023/release-notes/relnotes-2023.2.20231018.html

============================================================================================================

Installed:
generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch gperftools-libs-2.9.1-1.amzn2023.0.2.x86_64
libunwind-1.4.0-5.amzn2023.0.2.x86_64 nginx-1:1.24.0-1.amzn2023.0.2.x86_64
nginx-core-1:1.24.0-1.amzn2023.0.2.x86_64 nginx-filesystem-1:1.24.0-1.amzn2023.0.2.noarch
nginx-mimetypes-2.1.49-3.amzn2023.0.3.noarch

Complete!

About the dnf , based on explanation from Amazon:

DNF is the successor to YUM, the package management tool in Amazon Linux 2. DNF is similar to YUM in its usage. Many DNF commands are the same and with the same options as YUM commands. In a Command Line Interface (CLI) command, in most cases dnf replaces yum

Hope the article have solved your problem.

--

--