TroubleChute Logo
DEBIAN LINUX

Nginx Mainline Install Guide (Install latest Nginx)


Published: Jul 3, 2024
Last Edit: Jul 3, 2024
Linux Web Hosting
397 Words, 2 Minutes.

Watch the video:


Timestamps:
0:00 - Intro/Explanation
0:15 - Updating system
0:44 - Adding Nginx Mainline ppa
1:20 - Installing Nginx Mainline
1:37 - Verify Nginx Mainline is installed
1:55 - Enable Nginx as service

Why change how we install Nginx?

Installing Nginx from the normal app repository can result in outdated versions of Nginx being installed. This guide will be using Ubuntu, a Debian-based distro. Commands should work for both Ubuntu and other Debian-based distros.

For example:

1
2
sudo apt update
apt-cache madison nginx

To see which versions of Nginx are available from the apt database. I see:

1
2
3
     nginx | 1.18.0-6ubuntu14.4 | http://de.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
     nginx | 1.18.0-6ubuntu14.3 | http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages
     nginx | 1.18.0-6ubuntu14 | http://de.archive.ubuntu.com/ubuntu jammy/main amd64 Packages

Installling Nginx using sudo apt update && sudo apt install nginx would install 1.18. This sounds great, but you can install and use Nginx 1.27. Installing with the normal command would install a much older version. 1.18 lost support 3 years ago (20 Apr 2021)

This is not good.

What is better?

The best way to install Nginx is to follow the official install instructions. This should result in the latest Nginx Mainline being installed.

However, there’s an even better way. If you’re a serious about compression and other things you will likely want to use Brotli compression. This is not available without going through another installation process (it can be done for free, officially).

We can use other users’s install scripts or distributions. A fantastic repo I’d recommend using is Ondřej Surý’s Nginx PPA on launchpad.net. More info.

This comes with Brotli pre-installed!

Let’s do it!

Installing Nginx with Brotli

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
sudo apt update && sudo apt upgrade -y

# Uninstall existing Nginx:
sudo systemctl stop nginx
sudo apt-get autoremove nginx*

# Install mainline Nginx:
sudo add-apt-repository ppa:ondrej/nginx-mainline -y
sudo apt update
sudo apt install nginx-core nginx-common nginx nginx-full -y

# Verify Nginx Mainline version. This should show you the latest available verions on the server:
apt-cache policy nginx

# Enable Nginx as service:
systemctl status nginx
sudo systemctl start nginx
sudo systemctl enable nginx

Just like that you now have Nginx installed and ready to use! And best of all you can set up Brotli with just a few lines in your configuration files.

TroubleChute © Wesley Pyburn (TroubleChute)
Support Me Privacy Policy Cookies Policy Terms of Service Change privacy settings Contact