How to Install Latest Nginx Mainline on CentOS 8 Stream

For those using CentOS 8 Stream, you might have noticed that installing Nginx directly from its Appresteam does not install the latest stable or mainline version. It is pretty far behind where Nginx is stable, and Mainline is at the current time of its development.

For most, using the default Nginx that comes bundled with the CentOS App stream will be preferred. Still, the following tutorial will cover the steps needed to use newer versions for the latest features.


Updating Operating System

Update your CentOS Stream operating system to make sure all existing packages are up to date:

sudo dnf upgrade --refresh -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@centos-stream ~]$ sudo whoami

To set up an existing or new sudo account, visit our tutorial on adding a User to Sudoers on CentOS Stream.

To use the root account, use the following command with the root password to log in.


The tutorial will utilize the terminal, which can be found in your show applications menu.


How to Install Latest Nginx Mainline on CentOS 8 Stream

Situational. Remove Previous Nginx Installation

First, you need to remove any previous Nginx installations before installing Nginx Mainline.

Stop Nginx using the systemctl command as follows:

sudo systemctl stop nginx

Next, remove Nginx using the following command:

sudo dnf remove nginx

Create & Install Ngnix Repository

Now that you have successfully removed the old Nginx version, if you had it installed, to install Nginx mainline, you need to install the dependency for it first, which is dnf-utilities with the following command:

sudo dnf install dnf-utils -y

Once installed, use your favorite text editor, create the following file:

sudo nano /etc/yum.repos.d/nginx.repo

Next, you need to add the following code, which specifies the Nginx repository which we will use to install the latest Nginx mainline version:

name=nginx stable repo

name=nginx mainline repo

To save use (CTRL+O), then exit (CTRL+X).

Note, the latest stable directory repository is also added for those preferring the alternative option.

Install Latest Nginx Mainline

By default, the latest repository for stable Nginx packages is used first. However, you are going to install Nginx mainline, so you will need to run the following command to enable the mainline repository as follows:

sudo dnf config-manager --enable nginx-mainline

Next, install Nginx mainline as follows:

sudo dnf install nginx

Notice the version number that is being installed as below:

How to Install Latest Nginx Mainline on CentOS 8 Stream

Type Y, then press the ENTER KEY to proceed with the installation.

Note that you will see a pop-up that notifies you about importing the GPG key during the installation.


How to Install Latest Nginx Mainline on CentOS 8 Stream

Type Y, then press the ENTER KEY to complete the installation.

To verify the Nginx mainline version, use the following command to confirm:

nginx -v

Example output:

nginx version: nginx/1.21.4

By default, Nginx does not come enabled and is deactivated on installation. To activate your Nginx service, use:

sudo systemctl start nginx

To enable Nginx to be started on boot, use the following command:

sudo systemctl enable nginx

Lastly, check the status to verify that Nginx is working correctly:

systemctl status nginx

Example output:

How to Install Latest Nginx Mainline on CentOS 8 Stream

Congratulations, you have successfully installed the latest Nginx Mainline build on your server.

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

The tutorial has shown you how to install the latest Nginx Mainline build on your CentOS 8 Stream desktop or server. Overall, stability is always to use what comes officially in the App stream. However, often, these lack features since they are so outdated.

A note to make that 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!