Installing NGINX via package managers
The quickest, and easiest, way to install NGINX is to simply use your OS-provided version. Most of the time, these are kept fairly updated; however, for some Linux distributions focusing on stability, you may only have older versions of NGINX available. Sometimes, your Linux distribution may provide multiple versions of NGINX with different compile flags.
In general, before embarking on a more complex journey, we should check whether we can use the easy solution. For Red Hat Linux-based operating systems, we need to enable the EPEL repo first and then do the same:
yum install epel-release yum search nginx yum info PACKAGE_NAME yum install PACKAGE_NAME
For a Debian-based operating system, we first find the NGINX compiles available and then get the information for the one we want:
apt-cache search nginx apt-cache show PACKAGE_NAME apt install PACKAGE_NAME
If the version provided is current enough, then you’re ready to configure NGINX in the next chapter.
If the version provided by your distribution is too old, then NGINX provides packages for RHEL/CentOS distributions as well as Debian/Ubuntu distributions. We encourage you to visit the official NGINX website to make sure the version given by your distribution isn’t outdated.
NGINX-provided packages
To set up a yum
repository for RHEL/CentOS, create a file named /etc/yum.repos.d/nginx.repo
with the following contents:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/ gpgcheck=0 enabled=1
Replace OS
with rhel
or centos
, depending on the distribution used, and OSRELEASE
with 8
or 9
, for versions 8.x or 9.x, respectively. Afterward, NGINX can now be installed with yum
:
yum install nginx
For Debian-based distributions, we need to first use their signing key to authenticate the package signatures. Download the following file first from http://nginx.org/keys/nginx_signing.key.
Then, run the following command:
sudo apt-key add nginx_signing.key
With the key added, we can now add the NGINX repository to sources.list
found in /etc/apt/sources.list
. For Debian, we add the following lines:
deb http://nginx.org/packages/debian/ codename nginx deb-src http://nginx.org/packages/debian/ codename nginx
Here, codename
is either trixie
or bookworm
, depending on your version of Debian. For Ubuntu, we use the following dependencies:
deb http://nginx.org/packages/ubuntu/ codename nginx deb-src http://nginx.org/packages/ubuntu/ codename nginx
Here, codename
is either noble
, focal
, or bionic
, depending on your version of Ubuntu. Finally, we can install NGINX with the apt
command:
apt update apt install nginx
Now that we have learned how to install NGINX from repositories, let’s have a look at how we can compile it from the source and benefit from having custom modules that are not provided with the default NGINX.