Installing 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 if we can use the easy solution. For a Debian-based operating system, we first find the Nginx compiles available then get the info for the one we want:
apt-cache search nginx apt-cache show PACKAGE_NAME apt-get install PACKAGE_NAME
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
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.
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 6
or 7
, for versions 6.x or 7.x, respectively. Afterwards, 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 our 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
Where codename
is either jessie
or stretch
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
Where codename
is one of trusty
, xenial
, or zesty
depending on your version of Ubuntu. Finally, we can install Nginx with the apt-get
command option:
apt-get update
apt-get install nginx