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 updaterefreshes the package list, andsudo apt upgradeinstalls available updates. - Red Hat/CentOS (YUM):
sudo yum updaterefreshes and upgrades packages in one step.
bash
sudo apt update
sudo apt upgrade
# or for Red Hat-based systems
sudo yum updateExample
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 upgradewithoutapt updatefirst, which means package lists are outdated. - Not using
sudo, causing permission errors. - Interrupting the update process, which can corrupt packages.
- Confusing
apt upgradewithapt 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
| Command | Description | Distribution |
|---|---|---|
| sudo apt update | Refresh package lists | Debian/Ubuntu |
| sudo apt upgrade | Install available updates | Debian/Ubuntu |
| sudo apt full-upgrade | Upgrade and remove conflicting packages | Debian/Ubuntu |
| sudo yum update | Refresh and upgrade packages | Red Hat/CentOS |
| sudo dnf update | Refresh 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.