Why Update Your Linux System?

You might ask: “The system is working fine, why update it?” Actually, updates are like patching a phone or maintaining a car. Their purpose is:
- Fix Vulnerabilities: Patch known security holes to make it harder for hackers to exploit.
- Get New Features: For example, a new software version might add shortcuts or support new hardware.
- Improve Performance: New versions may optimize code for faster and more stable operation.

In short: Updates make the system safer and more functional, but be careful with methods to avoid issues.

Pre-Update Preparation

While not all updates cause data loss, it’s wise to back up important files (e.g., documents, photos) beforehand using a USB or other storage.

2. Identify Your Linux Distribution

Linux has many “flavors” (e.g., Ubuntu, CentOS, Fedora), each with different update commands. First, confirm your distribution:
- Ubuntu/Debian: Run lsb_release -a or cat /etc/os-release in the terminal.
- CentOS/RHEL: Run cat /etc/redhat-release.
- Fedora: Run cat /etc/os-release.

General Update Steps (For Mainstream Distributions)

Core Command: Gain Privileges + Update Packages

Linux requires administrator privileges for updates. Thus, most update commands use sudo (Superuser Do).

1. Ubuntu/Debian (Most Common for Beginners)

These use the apt command, similar to an app store for your system.

Step 1: Update Package List (Get Latest Software Info)

sudo apt update
  • Explanation: Fetches the latest package information from repositories (e.g., Ubuntu’s official repos), like “checking a store’s latest inventory.”

Step 2: Upgrade Installed Packages (Download & Install New Versions)

sudo apt upgrade
  • Explanation: Uses the updated list to download and install all available updates, like “purchasing items from the list.”

Step 3: Handle Dependencies (Optional, for Major Updates)

If you see kernel or library upgrades, use full-upgrade to manage complex dependencies:

sudo apt full-upgrade
  • Explanation: Automatically resolves package dependencies (e.g., upgrading Python from 3.8 to 3.9), preventing update interruptions.

2. CentOS/RHEL (Enterprise-Focused)

These use yum or dnf (a smarter yum replacement).

Step 1: Update Package List

sudo dnf check-update  # Recommended for CentOS 8
# For older CentOS 7: sudo yum check-update

Step 2: Upgrade Packages

sudo dnf update  # Recommended for CentOS 8
# For older CentOS 7: sudo yum update

3. Other Distributions (Brief Mention)

  • Arch Linux: Use pacman -Syu (sync repositories, then update all packages).
  • Fedora: Similar to CentOS, use sudo dnf update.
  • Domestic OS (e.g., Kylin): Based on apt, so commands match Ubuntu/Debian.

Common Issues & Solutions

1. Forgot to Use sudo?

Example Error: Running apt update directly (results in “permission denied”).
Fix: Add sudo to commands: sudo apt update.

2. Update Fails: “Failed to Download” or “Repo Unreachable”

  • Causes: Unstable network (e.g., campus Wi-Fi limits) or incorrect repo URLs.
  • Solutions:
  • Check network: Restart the router or use a mobile hotspot.
  • Change Repos: Switch to a domestic mirror (e.g., Alibaba Cloud, NetEase for Ubuntu).
  • Fix Locks: If “Lock error” occurs, run sudo rm /var/lib/apt/lists/lock to unlock.

3. Black Screen/No Boot After Update

  • Causes: Dependency conflicts or kernel updates causing boot issues (rare but possible).
  • Solutions:
  • Restart the computer (might resolve a stuck update).
  • Boot into “Recovery Mode” (Ubuntu: press Shift on startup; CentOS: “Rescue Mode”).
  • Last Resort: Boot from a Linux Live CD/USB and restore from backups.

4. Roll Back to Pre-Update Version?

  • Ubuntu: Use sudo apt history to find the update ID, then sudo apt rollback <ID> (supported in Ubuntu 16.04+).
  • General: Reinstall older software versions if the system works but updates are unwanted (not recommended; better to fix issues).

Summary: 4-Step Update Routine

  1. Backup Data: Save critical files first.
  2. Use sudo: Prefix all update commands with sudo.
  3. Choose Commands by Distribution: Ubuntu/Debian: sudo apt updatesudo apt upgrade.
  4. Stay Calm: Troubleshoot errors (e.g., network issues: change repo; dependency issues: sudo apt install -f).

Updating Linux is simple: “Check inventory (update), then buy items (upgrade)”. With practice, you’ll master it. For safety, update weekly (e.g., Sunday evenings) to maintain stability.

Xiaoye