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:
- Open Terminal (or connect via SSH)
- Ensure you have all of the prerequisites installed:
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring - Import the nginx signing key for apt:
curl | gpg --dearmor \ | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null - Create a sources
.listfile 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 - 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 - Update apt:
sudo apt update - Install nginx:
sudo apt install nginx