Introduction: The Nginx Adventure Begins
Welcome, intrepid sysadmin! You’re about to embark on a quest of epic proportions: installing the latest version of Nginx on your server. Whether you’re navigating the red-hued lands of CentOS, the debian-descended valleys of Ubuntu, or the green pastures of SUSE, we’ve got your back. Grab your sword (or rather, your terminal) and let’s conquer these servers!
Realm 1: CentOS, RHEL, AlmaLinux, Rocky Linux, and Fedora (The DNF/YUM Kingdom)
Our journey begins in the DNF/YUM Kingdom, a place where commands are consistent and the repositories are vast.
Step 1: Update Your System
Before venturing further, ensure your system is up to date. After all, nobody wants to fight bugs with outdated armor.
sudo dnf update -y
Step 2: Add the Nginx Repository
The latest version of Nginx isn’t in the default repositories, so we need to add the official Nginx repository. Think of this as recruiting a mighty warrior to your cause.
sudo tee /etc/yum.repos.d/nginx.repo <<EOL
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
EOL
Step 3: Install Nginx
With the repository added, summoning Nginx is as easy as a single command.
sudo dnf install nginx -y
Step 4: Start and Enable Nginx
Awaken the mighty Nginx and ensure it starts on boot.
sudo systemctl start nginx
sudo systemctl enable nginx
Realm 2: Ubuntu Server and Debian (The APT Dominion)
Next, we travel to the APT Dominion, where package management is as smooth as a bard’s song.
Step 1: Update Your System
Start by refreshing your system’s sources and upgrading your gear.
sudo apt update
sudo apt upgrade -y
Step 2: Add the Nginx Repository
Just like in the DNF/YUM Kingdom, we need the official Nginx repository.
sudo apt install curl gnupg2 ca-certificates lsb-release -y
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
For Debian, adjust the repository line accordingly:
echo "deb http://nginx.org/packages/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
Step 3: Install Nginx
With the repository added, install the latest version of Nginx.
sudo apt update
sudo apt install nginx -y
Step 4: Start and Enable Nginx
Summon Nginx to life and ensure it starts with your server.
sudo systemctl start nginx
sudo systemctl enable nginx
Realm 3: SUSE Linux Enterprise Server and openSUSE (The Zypper Zone)
Finally, we arrive at the Zypper Zone, where package management is robust and the commands are sharp.
Step 1: Update Your System
Begin by updating your system’s packages.
sudo zypper refresh
sudo zypper update -y
Step 2: Add the Nginx Repository
Add the official Nginx repository to your system.
sudo zypper addrepo -G -t yum https://nginx.org/packages/sles/12 nginx
sudo zypper addrepo -G -t yum https://nginx.org/packages/sles/15 nginx
sudo zypper addrepo -G -t yum https://nginx.org/packages/sles/15 nginx-stable
sudo rpm --import https://nginx.org/keys/nginx_signing.key
For openSUSE, adjust the repository line accordingly:
sudo zypper addrepo https://nginx.org/packages/opensuse/15 nginx
Step 3: Install Nginx
With the repository added, install Nginx.
sudo zypper install nginx
Step 4: Start and Enable Nginx
Bring Nginx to life and ensure it starts at boot.
sudo systemctl start nginx
sudo systemctl enable nginx
Conclusion: Victory is Yours!
Congratulations, brave sysadmin! You have successfully installed the latest version of Nginx on your chosen realm. Whether you prefer the familiarity of CentOS, the simplicity of Ubuntu, or the strength of SUSE, you now have the power of Nginx at your fingertips. Now go forth and serve those web pages with pride!