How to Install a Specific Version of NGINX on Linux Ubuntu: A Step-by-Step Guide

NGINX is a powerful, high-performance web server that powers many websites and web applications. Often, web administrators need to install a specific version of NGINX due to compatibility requirements or the need for certain features available only in particular releases. In this guide, we will show you how to install a specific version of NGINX on Linux Ubuntu.

Follow this step-by-step tutorial to install the desired version of NGINX on your Ubuntu server.

Prerequisites

Before we dive into the installation process, make sure you have the following prerequisites:

  1. A Linux Ubuntu server – Ensure you are running Ubuntu 18.04, 20.04, or the latest version.
  2. Root or sudo privileges – You need administrative access to install packages and modify system configurations.
  3. A stable internet connection – You’ll need to download the necessary NGINX packages from the official repositories.

Step 1: Update Your System

Start by updating your package list to ensure that all your system repositories are up to date. This helps avoid any issues during installation and ensures you are working with the latest available packages.

sudo apt update

Additionally, you may want to upgrade all existing packages to their latest versions:

sudo apt upgrade -y

This ensures your system is up to date, providing the best performance and security.

Step 2: Add the Official NGINX Repository

Although Ubuntu comes with NGINX in its default package repository, to install a specific version, you will need to use the official NGINX repository. Adding this repository ensures that you get access to various versions, including older and more stable releases.

To add the official NGINX repository, run the following command:

sudo add-apt-repository ppa:nginx/stable

After adding the repository, update the package list again:

sudo apt update

This ensures that the new repository is used for package installation.

Step 3: Search for Available NGINX Versions

Before installing a specific version of NGINX, you need to check which versions are available in the repository. You can do this using the following command:

apt list -a nginx

This will show you a list of all the NGINX versions available for installation. Identify the version number that you want to install from the list.

Step 4: Install a Specific Version of NGINX

Once you’ve identified the version you want, you can install it by specifying the version number in the installation command.

For example, if you want to install NGINX version 1.18.0, you can run the following command:

sudo apt install nginx=1.18.0-1ubuntu1

Make sure to replace 1.18.0-1ubuntu1 with the specific version you want to install, which you found in the previous step.

If you see a message that the version is held back or unavailable, check the exact version number or consider adding a different repository.

Step 5: Prevent NGINX from Upgrading

If you want to make sure that NGINX does not automatically upgrade to a newer version, you can “hold” the current version. This prevents the package from being updated during system upgrades.

To hold the NGINX package, run:

sudo apt-mark hold nginx

This ensures that the specified version will not be upgraded, even during a system update.

Step 6: Verify the Installation

Once the installation is complete, it’s important to verify that the correct version of NGINX is installed. You can do this by checking the version of NGINX installed:

nginx -v

This command will display the installed version of NGINX, confirming that the correct version is running.

Step 7: Start and Enable NGINX

Now that the installation is complete, you can start NGINX and enable it to run on boot using the following commands:

sudo systemctl start nginx
sudo systemctl enable nginx

This will ensure that NGINX starts automatically when your server boots up.

Step 8: Test NGINX

To confirm that NGINX is running correctly, open your web browser and navigate to your server’s IP address or domain name (e.g., http://your-server-ip). If everything is set up correctly, you should see the default NGINX welcome page.

Alternatively, you can also test NGINX from the terminal by running the following curl command:

curl -I http://localhost

You should receive an HTTP response from NGINX.

Step 9: Configure NGINX (Optional)

If you need to make any customizations, such as setting up virtual hosts or modifying server configurations, the NGINX configuration files are located in /etc/nginx/.

You can edit the main configuration file with:

sudo nano /etc/nginx/nginx.conf

Be sure to test your configuration changes before reloading NGINX:

sudo nginx -t

If everything looks good, reload NGINX to apply the changes:

sudo systemctl reload nginx

Conclusion

By following this step-by-step guide, you can easily install a specific version of NGINX on your Ubuntu server. Whether you’re managing a production server or a local development environment, installing a particular NGINX version can help you meet project requirements or maintain compatibility with other services.

If you want to prevent upgrades, remember to hold the NGINX package, ensuring that your desired version remains in use. Regularly check for any security updates for your installed version and apply them as necessary.

You may also like...

Leave a Reply