Debian is a Linux distro composed of free and open-source software (FOSS). It’s developed by the Debian Project, a community-driven project. It’s one of the oldest operating systems based on the Linux kernel. Debian is at the core of many popular operating systems like Ubuntu, Linux Mint, MX Linux, Deepin, and much more.
This guide will demonstrate how to keep Debian’s packages up-to-date from the terminal.
Keeping Debian up-to-date
A Linux operating system is a combination of numerous packages connected with each other in a very complex network. All these packages deliver all the necessary files and binaries that make the operating system.
These packages are generally updated regularly. It may be bug fixes, security patches, or feature improvements. It’s important to keep all the packages up-to-date.
Debian uses APT to manage packages. The package updates are directly available from the official Debian package repos. APT can also work with third-party repos. However, it’s up to you to determine whether the third-party repo is trustworthy and updating their packages.
We can use APT to perform a check whether any package update is available. If available, we can update the target packages.
It’s also possible to configure automatic updates on Debian using unattended upgrades.
Updating packages require root permission. To perform the actions demonstrated, you need to have access to the root user. Alternatively, you need a non-root user who can execute the sudo command. Learn more on managing sudo permission for users on Debian.
Checking for updates
Open up the terminal and run the following command.
As the output suggests, APT will check for updates on each of the repos configured and update its package catalog. If any update is available, APT will notify you that updates are available.
To check the list of available package updates, run the following APT command.
The APT cache is updated with the latest available package catalog. We now also know what package updates are available. Time to install them.
To upgrade a target package, run the following command. Here, APT will only upgrade the target package. If the package weren’t installed already, it wouldn’t be installed.
$ sudo apt –only-upgrade install <package_name>
To upgrade all the packages at once, run the following command instead. Here, APT will download and upgrade all the available package updates.
Before downloading and upgrading packages, APT will ask for confirmation to perform the action. If you don’t want APT to ask for confirmation, add the flag “-y”.
Updating APT cache and upgrading packages simultaneously
Instead of performing these steps simultaneously, we can combine them both in a single command. If you’re running the bash shell, then the following command will check for package updates and upgrade packages simultaneously.
$ sudo apt update && sudo apt upgrade -y
Here, the symbol “&&” ties both the update and upgrade commands together. It’s basically a logical AND operator. There are numerous bash operators and symbols that carry special functions and meanings. Check out this big list of bash operators and their implementations.
Automating Debian update
So far, we’ve updated Debian packages manually. However, manual updating is inconvenient in the long run, not to mention enterprise/professional environment where you may need to manage multiple remote servers at the same time. Updating all of them manually is a tedious process. It’s possible to use Ansible to manually update remote Debian/Ubuntu systems at once but running it manually regularly is not practical.
This is where we can use unattended upgrades. It’s a tool that will automatically check and download package updates whenever available. It requires a little bit of configuration.
First, we need to install the package. Open a terminal, update the APT cache, and install the package.
$ sudo apt update && sudo apt install unattended-upgrades
Next, we need to tweak the APT configuration file for unattended-upgrades. Open it in a text editor.
$ sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
Uncomment the following lines from the configuration file. It will tell the tool to automate the update process.
The configuration file is updated. Run the following dpkg configuration command to put it into action.
$ sudo dpkg-reconfigure –priority=low unattended-upgrades
After successful execution, a dialog box will appear on the terminal. Select “Yes”.
The tool will now automatically download and install updates on Debian. However, we need to make sure that it’s working as intended. Check the service status.
$ sudo systemctl status unattended-upgrades.service
It’s showing that the service status is Active (In Progress), meaning it’s working perfectly. Check out this guide on unattended upgrades for full in-depth info and demonstrations.
Updating Debian is a very simple task. Debian is a well-maintained project with up-to-date packages directly available from its package servers. All you need is to tell APT to do the job.
Debian follows a long-term release cycle. So, you don’t have to upgrade your distro often. If you’re using an older Debian, then instead of updating the packages, it’s recommended to upgrade the distro. At the time of writing this guide, Debian 10 is the latest stable release. Check out this guide on how to upgrade from Debian 9 to Debian 10.