Install Latest Nginx on Ubuntu | Generated by AI

Home 2026.02

Question: The command ‘nginx’ is not found on my system. It suggests installing nginx-core, nginx-extras, or nginx-light. What should I do next to get nginx working?

Answer:

You are on an Ubuntu (or Debian-based) system, and nginx is not installed yet. Here’s the recommended way to proceed in 2025/2026:

The versions suggested by apt (1.18.0) are very old (released in 2020). You almost certainly want a newer, supported version.

Method 1 – Official nginx repository (cleanest & gets latest stable version)

  1. Add the official nginx signing key and repository:
    sudo apt update
    sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring
    curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg
    echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
    echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
    
  2. Install nginx:
    sudo apt update
    sudo apt install nginx
    
  3. Verify:
    nginx -v
    # Should show something like: nginx version: nginx/1.26.x (or newer)
    sudo systemctl status nginx
    

Method 2 – Quick but older version (if you just want to test right now)

If you don’t care about getting the latest version and just want nginx running immediately:

sudo apt update
sudo apt install nginx
# This will usually install nginx-core or the default variant

After either method, your original config should work once you:

Quick summary – what most people should run right now

# Recommended – get current stable nginx from official source
sudo apt update
sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

sudo apt update
sudo apt install nginx

nginx -v

After this you can use the nginx command and your directory listing setup at /movies/ should work.

References:


Back Donate