How to Install Latest Nginx Mainline on Rocky Linux 8

For those using Rocky Linux 8, 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 Rocky Linux will be preferred, but for those wanting to use newer versions for the latest features, the following tutorial will cover the steps needed to do this.

Prerequisites

  • Recommended OS: Rocky Linux 8.+.
  • User account: A user account with sudo or root access.

Update Operating System

Update your Rocky Linux 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@rockylinux ~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on How to Add a User to Sudoers on Rocky Linux.

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

su

Advertisement


Remove Previous Nginx Installation

First, you need to remove any previous Nginx installations that are active 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

Adding the 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 version:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

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


Advertisement


Install the 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 yum-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 Rocky Linux 8

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

This is safe to do and is required to finish installing Nginx mainline successfully. Type “Y” and press “ENTER”.

How to Install Latest Nginx Mainline on Rocky Linux 8

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

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

nginx -v

Example output:

How to Install Latest Nginx Mainline on Rocky Linux 8

Congratulations, you have successfully installed the latest Nginx mainline version from your old Nginx version that came with the Rocky Linux App stream.

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

Advertisement


Comments and Conclusion

The tutorial has shown you how to install the Nginx repository so you can pull either Nginx stable or mainline latest versions on your Rocky Linux 8 server. Stability is always to use what comes officially in the App stream on Rocky Linux. However, often, these lack features since they are so outdated.

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.

Leave a Comment