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. In fact, it is quite 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 newest features, the following tutorial will cover the steps needed to do this.
- Recommended OS: Rocky Linux 8.+
- User account: A user account with sudo or root access.
- Required Packages: dnf-utils
Updating Operating System
Update your Rocky Linux 8 operating system to make sure all existing packages are up to date:
sudo dnf update && sudo dnf upgrade -y
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:
name=nginx stable repo
name=nginx mainline repo
To save use (CTRL+O), then exit (CTRL+X).
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:
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.
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:
Congratulations, you have successfully installed the latest Nginx mainline version from your old Nginx version that came with the Rocky Linux App stream.
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 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 quite safe compared to other software where bugs and instability could be present. Nginx does a fantastic job in keeping its web application running smoothly.