On Debian/Ubuntu:
sudo apt update && sudo apt install nginx
This command updates the package list and installs the NGinX package from the default repositories.
On RHEL/CentOS/Rocky Linux:
sudo yum install nginx
This command installs NGinX from the default system repositories.
If you want to get the latest version, use the next variant or build your custom nginx.
To install the latest version of NGinX, you can use the official NGinX repository.
On Debian/Ubuntu:
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
sudo sh -c 'echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" > /etc/apt/sources.list.d/nginx.list'
sudo sh -c 'echo "deb-src http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" >> /etc/apt/sources.list.d/nginx.list'
sudo apt update && sudo apt install nginx
On RHEL/CentOS/Rocky Linux:
sudo tee /etc/yum.repos.d/nginx.repo <<EOF
[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
EOF
sudo yum install nginx
If you need the latest features or custom modules, you can build NGinX from source.
Install dependencies:
sudo apt update
sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
sudo yum groupinstall 'Development Tools'
sudo yum install pcre pcre-devel zlib zlib-devel openssl openssl-devel
Download the latest NGinX source code from NGinX.org:
wget http://nginx.org/download/nginx-1.27.2.tar.gz
tar -zxvf nginx-1.27.2.tar.gz
cd nginx-1.27.2
Configure and compile NGinX:
./configure
make
sudo make install
Start NGinX:
sudo /usr/local/nginx/sbin/nginx
Building from source allows you to customize NGinX with specific modules and optimizations.
sudo systemctl start nginx
sudo systemctl restart nginx
sudo systemctl reload nginx # For reloading the config without downtime