Skip to content

Instantly share code, notes, and snippets.

@withakay
Last active September 14, 2025 13:07
Show Gist options
  • Save withakay/3834bc9566c272dab6e29c6d2ece9411 to your computer and use it in GitHub Desktop.
Save withakay/3834bc9566c272dab6e29c6d2ece9411 to your computer and use it in GitHub Desktop.
Ubuntu Update

The Ubuntu Update Script

A comprehensive Ubuntu update script

. Get the Raw URL:

  • After creating, click on the "Raw" button
  • Copy the URL (it will look like: https://gist.githubusercontent.com/YOUR_USERNAME/GIST_ID/raw/ubuntu-update.sh)

One-Line Commands to Run

Once you have your raw gist URL, you can use these one-liners:

Option 1: Download and execute directly (less secure)

curl -sSL https://gist.githubusercontent.com/withakay/3834bc9566c272dab6e29c6d2ece9411/raw/ubuntu-update.sh | sudo bash

Option 2: Download, review, then execute (more secure)

curl -sSL https://gist.githubusercontent.com/withakay/3834bc9566c272dab6e29c6d2ece9411/raw/ubuntu-update.sh -o /tmp/update.sh && chmod +x /tmp/update.sh && sudo /tmp/update.sh

Security Considerations

⚠️ Important: Running scripts directly from the internet with curl | sudo bash can be risky. Consider:

  1. Always review scripts before running them
  2. Use HTTPS URLs only
  3. Consider downloading first, reviewing, then executing
  4. Keep the gist private if it's for personal use only

Alternative: Create an Alias

For frequent use, add this to your ~/.bashrc:

alias update-system='curl -sSL https://gist.githubusercontent.com/YOUR_USERNAME/GIST_ID/raw/ubuntu-update.sh | sudo bash'

Then you can simply run:

update-system
#!/bin/bash
# Ubuntu System Update Script
# Performs full system update with proper error handling
set -e # Exit on error
# Colours for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Colour
# Function to print coloured messages
print_message() {
echo -e "${2}${1}${NC}"
}
print_message "Starting Ubuntu System Update..." "$GREEN"
print_message "===============================" "$GREEN"
# Check if running with sudo
if [ "$EUID" -ne 0 ]; then
print_message "This script requires sudo privileges. Re-running with sudo..." "$YELLOW"
exec sudo "$0" "$@"
fi
# Update package lists
print_message "\n📦 Updating package lists..." "$GREEN"
apt update || { print_message "Failed to update package lists" "$RED"; exit 1; }
# Upgrade packages
print_message "\n⬆️ Upgrading packages..." "$GREEN"
apt upgrade -y || { print_message "Failed to upgrade packages" "$RED"; exit 1; }
# Perform distribution upgrade
print_message "\n🚀 Performing distribution upgrade..." "$GREEN"
apt dist-upgrade -y || { print_message "Failed to perform dist-upgrade" "$RED"; exit 1; }
# Remove unnecessary packages
print_message "\n🧹 Removing unnecessary packages..." "$GREEN"
apt autoremove -y || { print_message "Failed to autoremove packages" "$RED"; exit 1; }
# Clean package cache
print_message "\n🧽 Cleaning package cache..." "$GREEN"
apt autoclean || { print_message "Failed to clean package cache" "$RED"; exit 1; }
# Check if reboot is required
if [ -f /var/run/reboot-required ]; then
print_message "\n⚠️ System reboot required!" "$YELLOW"
print_message "Please reboot your system to complete the updates." "$YELLOW"
else
print_message "\n✅ All updates completed successfully!" "$GREEN"
fi
print_message "\nSystem update process finished." "$GREEN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment