Skip to main content
A single script that detects your distribution and runs the correct update commands. Supports Debian/Ubuntu, RHEL-family (AlmaLinux, Rocky, Fedora, CentOS, CloudLinux), Arch, openSUSE, and Alpine.
This script is for VPS and Bare Metal customers managing their own servers. Web Hosting and WordPress Hosting customers do not need to manage OS-level updates.

The Script

update.sh
#!/bin/bash
set -euo pipefail

# Detect distribution
if [ -f /etc/os-release ]; then
    . /etc/os-release
    DISTRO="$ID"
else
    echo "Cannot detect distribution. /etc/os-release not found."
    exit 1
fi

echo "Detected distribution: $DISTRO"
echo "Starting system update..."

case "$DISTRO" in
    debian|ubuntu)
        apt update
        apt upgrade -y
        apt autoremove -y
        apt autoclean
        ;;
    almalinux|rocky|centos|rhel|cloudlinux|fedora)
        if command -v dnf &>/dev/null; then
            dnf upgrade -y
            dnf autoremove -y
            dnf clean all
        else
            yum update -y
            yum autoremove -y
            yum clean all
        fi
        ;;
    arch|manjaro)
        pacman -Syu --noconfirm
        # Remove orphaned packages
        ORPHANS=$(pacman -Qdtq 2>/dev/null) || true
        if [ -n "$ORPHANS" ]; then
            pacman -Rns --noconfirm $ORPHANS
        fi
        ;;
    opensuse*|sles)
        zypper refresh
        zypper update -y
        zypper clean --all
        ;;
    alpine)
        apk update
        apk upgrade
        # Remove cached packages
        apk cache clean 2>/dev/null || rm -rf /var/cache/apk/*
        ;;
    *)
        echo "Unsupported distribution: $DISTRO"
        exit 1
        ;;
esac

echo "Update complete."

# Show if a reboot is required (Debian/Ubuntu)
if [ -f /var/run/reboot-required ]; then
    echo "*** A reboot is required to apply kernel updates. ***"
fi

# Show if a reboot is required (RHEL-family)
if command -v needs-restarting &>/dev/null; then
    if needs-restarting -r &>/dev/null; then
        true
    else
        echo "*** A reboot is required to apply kernel updates. ***"
    fi
fi

Usage

# Download and run directly
curl -fsSL https://raw.githubusercontent.com/your-repo/update.sh | bash

# Or save locally and run
curl -fsSL https://raw.githubusercontent.com/your-repo/update.sh -o /usr/local/bin/update.sh
chmod +x /usr/local/bin/update.sh
update.sh
Review any script before running it with curl | bash. You can inspect the script first by removing | bash from the command.

Automating with Cron

To run updates automatically on a schedule:
crontab -e
# Run updates every Sunday at 3:00 AM
0 3 * * 0 /usr/local/bin/update.sh >> /var/log/auto-update.log 2>&1
Automated updates are convenient but can introduce breaking changes. For production servers, consider running the script manually or scheduling it during a maintenance window where you can monitor the output.

What Each Package Manager Does

DistributionUpdateCleanup
Debian / Ubuntuapt update + apt upgradeapt autoremove + apt autoclean
RHEL familydnf upgrade (or yum update)dnf autoremove + dnf clean all
Archpacman -SyuRemoves orphaned packages
openSUSEzypper updatezypper clean --all
Alpineapk upgradeClears APK cache