Question

How to install the latest stable Nginx version on CentOS 8?

If you have a CentOS 8 server you might have noticed that installing Nginx directly with the sudo dnf install nginx command does not install the latest stable Nginx version.

Here’s how you could install the latest Nginx available on CentOS 8!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
October 17, 2020
Accepted Answer

Before getting started, make sure to follow our Initial Server Setup Guide for CentOS 8 guide:

https://www.digitalocean.com/community/tutorials/initial-server-setup-with-centos-8

Removing your old Nginx installation

If you already have Nginx installed, you would need to stop it and then remove the current installation:

  • Stop Nginx:
  1. sudo systemctl stop nginx
  • Then remove the old installation:
  1. sudo dnf remove nginx

Adding the Ngnix repository

Once you’ve removed the old Nginx version, you will need to first install the dnf utilities:

  1. sudo dnf install dnf-utils

Then using your favorite text editor, create the following file:

  1. vim /etc/yum.repos.d/nginx.repo

After that add the following content which specifies the Nginx repository which we will use to install the latest Nginx version:

/etc/yum.repos.d/nginx.repo
[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

Save the file and exit.

With that, you are ready to install Nginx!

Installing the latest Nginx version

With the nginx.repo that we just added, dnf will install the stable Nginx version. In case you want to, you could use the Mainline, which includes some new features, you need to run the following command:

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

For more information about the difference between the Stable and the Mainline Nginx versions, make sure to check the official Nginx blog here:

https://www.nginx.com/blog/nginx-1-6-1-7-released/

Once you’ve specified the Nginx stable repository, you have to run the following command to install Nginx:

  1. sudo dnf install nginx

You will get a prompt asking you to accept the GPG key:

Output
Importing GPG key 0x7BD9BF62:
 Userid     : "nginx signing key <signing-key@nginx.com>"
 Fingerprint: 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
 From       : https://nginx.org/keys/nginx_signing.key
Is this ok [y/N]: <^y<^>

Just click y and then press Enter.

With that, the latest stable Nginx version will be installed on your CentOS 8 server!

Starting and enabling Nginx

Finally, make sure to start Nginx with the following command:

  1. sudo systemctl start nginx

And then make sure to enable it so that in case that your server gets rebooted, Nginx would start automatically on boot:

  1. sudo systemctl enable nginx

Video Demo

Conclusion

This is pretty much it! Now you have the latest Nginx version installed and up and running!

For more information on how to get started with Nginx, make sure to check the steps from the following tutorial:

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-8

I hope that this helps!

alexdo
Site Moderator
Site Moderator badge
February 23, 2022

Hello there,

In addition to what has already been mentioned, I wanted to point out that CentOS Linux 8 has reached End Of Life (EOL) on December 31st, 2021.

I would strongly recommend planning either migration to another OS like Debian or Ubuntu, or upgrading to CentOS Stream.

I personally believe that the safest way to do this is to follow these steps here:

  • Spin up a new Droplet with the desired OS
  • Install the necessary services (webserver, sql server, etc.)
  • After that using rsync for example copy over your files and migrate your databases
  • Then test your website and server fully to make sure that everything is working as expected
  • Finally, change your DNS to point to the new Droplet

Regards, Alex

alexdo
Site Moderator
Site Moderator badge
February 22, 2022

Hello there,

In addition to what has already been mentioned, I wanted to point out that CentOS Linux 8 has reached End Of Life (EOL) on December 31st, 2021.

I would strongly recommend planning either migration to another OS like Debian or Ubuntu, or upgrading to CentOS Stream.

I personally believe that the safest way to do this is to follow these steps here:

  • Spin up a new Droplet with the desired OS
  • Install the necessary services (webserver, sql server, etc.)
  • After that using rsync for example copy over your files and migrate your databases
  • Then test your website and server fully to make sure that everything is working as expected
  • Finally, change your DNS to point to the new Droplet

Regards, Alex

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.