Learn to install, manage, and configure Nginx on Ubuntu using apt, with notes for RHEL/CentOS users.
Learn how to install, manage, and configure Nginx on Ubuntu (or any Debian-based distribution) using apt. For CentOS or RHEL-based systems, swap apt with yum.
All commands below assume you have sudo privileges.
If you’re on RHEL/CentOS, use yum install nginx and yum update -y instead of apt.
Start by refreshing the local package index to fetch the latest metadata.
Copy
Ask AI
sudo apt update -y
Example output:
Copy
Ask AI
bob@alpine-host:~$ sudo apt update -yGet:1 http://security.ubuntu.com/ubuntu focal-security InRelease [128 kB]...Fetched 34.3 MB in 3s (10.7 MB/s)Reading package lists... DoneBuilding dependency treeReading state information... Done47 packages can be upgraded. Run 'apt list --upgradable' to see them.
Clear any clutter from your terminal before moving on:
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: inactive (dead)
Start Nginx and confirm it’s running:
Copy
Ask AI
sudo systemctl start nginxsudo systemctl status nginx
Now the service should be active (running):
Copy
Ask AI
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2025-02-05 11:59:11 EST; 5s ago