How to install the latest stable Nginx version on CentOS 8?

Posted October 17, 2020 9.1k views
NginxCentOSCentOS 8

If you have a CentOS 8 server you might have noticed that installing Nginx directly with the sudo dnf install nginx command does not install the latest stable Nginx version.

Here’s how you could install the latest Nginx available on CentOS 8!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Before getting started, make sure to follow our Initial Server Setup Guide for CentOS 8 guide:

Removing your old Nginx installation

If you already have Nginx installed, you would need to stop it and then remove the current installation:

  • Stop Nginx:
  • sudo systemctl stop nginx
  • Then remove the old installation:
  • sudo dnf remove nginx

Adding the Ngnix repository

Once you’ve removed the old Nginx version, you will need to first install the dnf utilities:

  • sudo dnf install dnf-utils

Then using your favorite text editor, create the following file:

  • vim /etc/yum.repos.d/nginx.repo

After that add the following content which specifies the Nginx repository which we will use to install the latest Nginx version:

name=nginx stable repo

name=nginx mainline repo

Save the file and exit.

With that, you are ready to install Nginx!

Installing the latest Nginx version

With the nginx.repo that we just added, dnf will install the stable Nginx version. In case you want to, you could use the Mainline, which includes some new features, you need to run the following command:

  • sudo yum-config-manager --enable nginx-mainline

For more information about the difference between the Stable and the Mainline Nginx versions, make sure to check the official Nginx blog here:

Once you’ve specified the Nginx stable repository, you have to run the following command to install Nginx:

  • sudo dnf install nginx

You will get a prompt asking you to accept the GPG key:

Importing GPG key 0x7BD9BF62:
 Userid     : "nginx signing key <>"
 Fingerprint: 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
 From       :
Is this ok [y/N]: <^y<^>

Just click y and then press Enter.

With that, the latest stable Nginx version will be installed on your CentOS 8 server!

Starting and enabling Nginx

Finally, make sure to start Nginx with the following command:

  • sudo systemctl start nginx

And then make sure to enable it so that in case that your server gets rebooted, Nginx would start automatically on boot:

  • sudo systemctl enable nginx

Video Demo


This is pretty much it! Now you have the latest Nginx version installed and up and running!

For more information on how to get started with Nginx, make sure to check the steps from the following tutorial:

I hope that this helps!

by Brian Boucheron
When you first create a new CentOS 8 server, there are a few configuration steps that you should take early on as part of the basic setup. This will increase the security and usability of your server and will give you a solid foundation for subsequent actions. This guide will cover setting up a non-root user with sudo, and setting up a basic firewall.

***********How to install the latest stable Nginx version cpanel and ssl on CentOS 8?*