For those using openSUSE 15 Leap, 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 openSUSE 15 Leap.
Table of Contents
- Recommended OS: openSUSE Leap – 15.x
- User account: A user account with sudo or root access.
Update Operating System
Update your openSUSE operating system to make sure all existing packages are up to date:
sudo zypper refresh
The tutorial will be using the sudo command and assuming you have sudo status.
To verify sudo status on your account:
Example output showing sudo status:
[joshua@opensuse ~]$ sudo whoami root
To set up an existing or new sudo account, visit our tutorial on adding a User to Sudoers on openSUSE.
To use the root account, use the following command with the root password to log in.
Remove Previous Nginx Installation
First, you need to remove any previous Nginx installations before installing the new Nginx versions to avoid conflict.
Stop Nginx using the systemctl command as follows:
sudo systemctl stop nginx
Next, remove Nginx using the following command:
sudo zypper remove nginx
Import Ngnix Repositories
Now that you have successfully removed the old Nginx version, if you had it installed, to install the new repositories directly from Nginx, you need to install the dependencies first with the following command.
sudo zypper install curl ca-certificates gpg2
Option 1. Import Nginx Mainline Repository
To set up and import the Nginx Mainline repository, run the following command in your terminal:
sudo zypper addrepo --gpgcheck --type yum --refresh --check \ 'http://nginx.org/packages/mainline/sles/$releasever_major' nginx-mainline
Option 2. Import Nginx Stable Repository
The same as Nginx Mainline as above, for Nginx Stable, use the following command in your terminal:
sudo zypper addrepo --gpgcheck --type yum --refresh --check \ 'http://nginx.org/packages/sles/$releasever_major' nginx-stable
Import GPG Key
Using the curl command, import the GPG key so the zypper package manager can verify the authenticity of the Nginx mainline packages:
curl -o /tmp/nginx_signing.key https://nginx.org/keys/nginx_signing.key
Next, it is recommended to test and verify the download file contains the proper key. To do this, use the following command in your terminal:
gpg --with-fingerprint /tmp/nginx_signing.key
The example output should appear:
pub 2048R/7BD9BF62 2011-08-19 [expires: 2024-06-14] Key fingerprint = 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 uid nginx signing key <firstname.lastname@example.org>
Once done, complete the GPG key import by executing the following command:
sudo rpmkeys --import /tmp/nginx_signing.key
Once imported, force the metadata cache to be updated.
sudo zypper ref -f
Install Nginx Mainline or Stable
Proceed to install Nginx on openSUSE with the repository you imported. By default, you should have imported one of the two on offer.
sudo zypper install nginx
Type Y and press the ENTER KEY to proceed and complete the installation.
Note that you may be prompted to keep or replace your existing /etc/nginx/nginx.conf configuration file during the installation. It is recommended to keep your current configuration file by pressing (n). A copy will be made regardless of the maintainer’s version, and you can also check this in the future.
Verify if Nginx was installed successfully and to the latest version by running the following command:
sudo nginx -v
Example output (Nginx Mainline Example)
nginx version: nginx/1.21.3
As above, the version installed at the time of writing successfully is the latest Nginx Mainline version.
By default, Nginx should be enabled if it is not activated. use:
sudo systemctl enable nginx --now
Example output if successful:
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
Verify the status of Nginx:
sudo systemctl status nginx
And that’s it, you have installed the latest Nginx version.
How to Keep Nginx Updated
For future updates, all you need to do is run the zypper package manager as you would check your system for updates as per usual.
sudo zypper refresh
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 openSUSE Leap 15 system.
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.