Install nginx-1.20.2 on Ubuntu 20.04

I am using Ubuntu 20.04 and i have installed nginx using sudo apt update sudo apt install nginx

But after installation when i do nginx -V to check version it always shows 1.18 version instead of latest version.

How i can install latest stable version of nginx on ubuntu 20.04?

1 Answer

If you want to install version 1.20.2 specifically, you will need to add the official nginx repository to your Sources list.

Here is how you do it:

  1. Open Terminal (or connect via SSH)
  2. Ensure you have all of the prerequisites installed:
    sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
  3. Import the nginx signing key for apt:
    curl | gpg --dearmor \ | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
  4. Create a sources .list file for apt:
    echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list
  5. Pin the repository to ensure the nginx packages are installed instead of the Ubuntu-provided packages:
    echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \ | sudo tee /etc/apt/preferences.d/99-nginx
  6. Update apt:
    sudo apt update
  7. Install nginx:
    sudo apt install nginx
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like