How to Install/Upgrade Nginx Mainline/Stable on Rocky Linux 8

For those using Rocky Linux 8, you might have noticed that installing Nginx directly from its repository does not install the latest stable or mainline version. This is a common trend in most distributions that focus on the stability of packages and provide only urgent bug or security updates until the subsequent major distribution.

For most, using the default Nginx that comes bundled with the repository will be preferred, but often many require and want the latest version of stable or mainline for updated features.

The following tutorial will cover installing the last stable or mainline versions of Nginx on Rocky Linux 8 using the official repository from with the command line terminal. The tutorial will cover how to import both versions and enable or disable the repositories depending on your preference.

Update Rocky Linux 8

Before you begin, update your system to ensure all packages are up-to-date to avoid conflicts.

sudo dnf upgrade --refresh

Remove Previous Nginx Installation

First, you need to remove any previous Nginx installations before installing the new Nginx versions to avoid conflict.

First, back up your Nginx configuration for safekeeping.

sudo mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old

Stop Nginx using the systemctl command as follows.

sudo systemctl stop nginx

Next, remove Nginx using the following command.

sudo dnf autoremove nginx*

Import Repositories

The task is to import the Nginx’s repository, which will give you at all times the latest version available. This is the best method of installing Nginx over all other techniques for those wanting the latest versions.

Use the following command to import the Nginx mainline and stable. By default, the stable will be enabled, but later on, the tutorial will show you how to enable mainline over the stable version.

Import Nginx Mainline Repository

sudo tee /etc/yum.repos.d/nginx-mainline.repo<<EOF

name=nginx mainline repo


Users with aarch architecture, replace in the above command baseurl= with baseurl=

Import Nginx Stable Repository

sudo tee /etc/yum.repos.d/nginx-stable.repo<<EOF

name=nginx stable repo


Users with aarch architecture, replace in the above command baseurl= with baseurl=

Install Nginx

By default, the stable version is enabled. The first task is to enable the repository you imported. First, you need to install the dnf-utils package.

sudo dnf install dnf-utils -y

Next, the tutorial will enable the mainline version; users that want to install the stable version do not need to use the following command.

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

In the case of the tutorial time of creation, a newer version of the stable was just released with a higher version from the mainline. So, when installing Nginx, it will automatically pick the highest version number from all repositories, so in this case, disable the stable repository using the following command.

sudo yum-config-manager --disable nginx-stable

This same method can disable the mainline version if you want to remove nginx and re-install the stable variant. They are just examples of how to switch versions.

Now, install the Nginx mainline.

sudo dnf install nginx

At this point, you have installed the latest version of Nginx from its official repository with the tutorial installing the mainline version. Still, you can ideally not enable the mainline and just install the latest stable instead.

Configure Firewall

If you are not replacing an existing Nginx service and installing Nginx for the first time, you may need to configure the firewall for HTTP and HTTPS traffic. An example of how to do this is below:

To allow HTTP traffic use the following command:

sudo firewall-cmd --permanent --zone=public --add-service=http

To allow HTTPS traffic use the following command:

sudo firewall-cmd --permanent --zone=public --add-service=https

Once done, you need to make the changes effective by reloading the firewall:

sudo firewall-cmd --reload

Comments and Conclusion

Overall, using the latest stable Nginx or Mainline versions is relatively safe compared to other software where bugs and instability could be present. Nginx does a fantastic job in keeping its web application running smoothly.


Like to get automatic updates? Follow us on one of our social media accounts!