0
0
Linux-cliHow-ToBeginner · 3 min read

How to Update Linux System: Simple Commands Explained

To update a Linux system, use the package manager commands like sudo apt update && sudo apt upgrade for Debian-based systems or sudo yum update for Red Hat-based systems. These commands refresh package lists and install the latest updates safely.
📐

Syntax

Linux system updates depend on the package manager your distribution uses. Here are the common commands:

  • Debian/Ubuntu (APT): sudo apt update refreshes the package list, and sudo apt upgrade installs available updates.
  • Red Hat/CentOS (YUM): sudo yum update refreshes and upgrades packages in one step.
bash
sudo apt update
sudo apt upgrade

# or for Red Hat-based systems
sudo yum update
💻

Example

This example shows how to update a Debian or Ubuntu system by refreshing package lists and then upgrading installed packages.

bash
sudo apt update && sudo apt upgrade -y
Output
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages will be upgraded: bash coreutils libc-bin libc6 4 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 5 MB of archives. After this operation, 1 MB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 bash amd64 5.0-6ubuntu1.1 [600 kB] Fetched 5 MB in 2s (2,500 kB/s) (Reading database ... 200000 files and directories currently installed.) Preparing to unpack .../bash_5.0-6ubuntu1.1_amd64.deb ... Unpacking bash (5.0-6ubuntu1.1) over (5.0-6ubuntu1) ... Setting up bash (5.0-6ubuntu1.1) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
⚠️

Common Pitfalls

Common mistakes when updating Linux include:

  • Running apt upgrade without apt update first, which means package lists are outdated.
  • Not using sudo, causing permission errors.
  • Interrupting the update process, which can corrupt packages.
  • Confusing apt upgrade with apt full-upgrade (the latter can remove packages).
bash
sudo apt upgrade
# Wrong: This upgrades without refreshing package lists first

sudo apt update && sudo apt upgrade
# Right: Refreshes package lists before upgrading
📊

Quick Reference

CommandDescriptionDistribution
sudo apt updateRefresh package listsDebian/Ubuntu
sudo apt upgradeInstall available updatesDebian/Ubuntu
sudo apt full-upgradeUpgrade and remove conflicting packagesDebian/Ubuntu
sudo yum updateRefresh and upgrade packagesRed Hat/CentOS
sudo dnf updateRefresh and upgrade packages (newer Red Hat)Fedora/Red Hat

Key Takeaways

Always run sudo apt update before sudo apt upgrade on Debian-based systems.
Use sudo yum update or sudo dnf update for Red Hat-based systems.
Never interrupt the update process to avoid package corruption.
Use sudo to ensure you have the right permissions.
Understand the difference between upgrade and full-upgrade to avoid unintended removals.