Updating System Packages

Introduction to Updating System Packages

Welcome to the exciting journey into system automation with shell scripts. As part of our first step, we will delve into the process of updating system packages. We will dive into packages and package managers, then see some practical examples of how to automate keeping your packages up-to-date.

Let's get started!

Understanding Packages

Packages are collections of files, metadata, and scripts used to install software on a computer. They bundle all the components necessary to run a program, including binaries, configuration files, documentation, and dependencies.

Repositories are structured storage locations from which software packages can be retrieved and installed on your system. They act as central hubs where developers upload their software packages online, and users download them.

Package Managers

In Unix-like operating systems, package management systems (PMS) handle the installation, upgrade, configuration, and removal of these software packages. Advanced Packaging Tool (APT) is a package management system used for handling packages on Debian-based Linux distributions like Ubuntu. apt-get is a command-line tool provided by APT that can be used for handling packages in shell scripts. With this understanding of packages and package managers, let's start writing a script to update them.

Viewing Installed Packages

We can see the list of installed packages by running:

 apt list --installed

The output of this command can be very lengthy (over 300 lines). Let's take a look at a few important lines:

...
bash/focal-updates,focal-security,now 5.0-6ubuntu1.2 amd64 [installed]
git/now 1:2.43.0-0ppa1~ubuntu20.04.1 amd64 [installed,upgradable to: 1:2.45.2-0ppa1~ubuntu20.04.1]
...

Let's break down the first line:

  • bash: The name of the package.
  • focal-updates,focal-security: The repositories where this version of the package is available
  • now: Indicates the status of the package (currently installed).
  • 5.0-6ubuntu1.2: The version of the package that is installed.
  • amd64: The architecture for which the package is built (64-bit in this case).
  • [installed]: Indicates that the package is currently installed on your system.

We can see that the bash package is up to date with the version 5.0-6ubuntu1.2. The git package is currently at version 1:2.43.0..., but we can see it is upgradeable to version 1:2.45.2....

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal