Lesson 6.1: APT Package Manager
APT (Advanced Package Tool) is Ubuntu's traditional package management system. It's powerful, reliable, and deeply integrated with the operating system, making it perfect for system software and libraries.
Why APT? APT handles complex dependency resolution automatically, provides system-wide updates, and maintains package integrity through cryptographic signatures.
Understanding APT
APT is a front-end to the dpkg package manager:
- dpkg: Low-level package manager (handles individual .deb files)
- APT: High-level package manager (handles repositories and dependencies)
- apt-cache: Query package information
- apt-get: Traditional APT interface (still widely used)
Basic APT Commands
Let's start with essential APT commands you'll use daily:
Update Package Lists
Always update before installing new software:
$ sudo apt update
Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Fetched 384 kB in 1s (452 kB/s)
Reading package lists... Done
Upgrade Packages
Upgrade all installed packages to latest versions:
$ sudo apt upgrade
Reading package lists... Done
Building dependency tree... Done
Calculating upgrade... Done
The following packages will be upgraded:
firefox (119.0.1-1build1 -> 120.0-1build1)
libssl1.1 (3.0.2-0ubuntu1.7 -> 3.0.2-0ubuntu1.8)
Do you want to continue? [Y/n] Y
Install Packages
Install new software with a single command:
$ sudo apt install git
Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
git git-man liberror-perl-perl libgit2-34 libx11-6
Suggested packages:
git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb
Do you want to continue? [Y/n] Y
Remove Packages
Uninstall software you no longer need:
$ sudo apt remove git
Reading package lists... Done
Building dependency tree... Done
The following packages will be REMOVED:
git git-man libgit2-34
Do you want to continue? [Y/n] Y
Searching for Packages
Find software using APT's search capabilities:
Basic Search
$ apt search web browser
firefox/jammy-updates,jammy-security 120.0-1build1 amd64
Safe and easy web browser from Mozilla
chromium-browser/jammy-updates,jammy-security 1:108.0.5359.124-0ubuntu0.1 amd64
Chromium web browser, open-source version of Chrome
lynx/jammy 2.8.9rel.1-2build1 amd64
Classic text-based web browser
Detailed Search
Get more information about packages:
$ apt show firefox
Package: firefox
Version: 120.0-1build1
Priority: optional
Section: web
Maintainer: Ubuntu Mozilla Team
Description-en: Safe and easy web browser from Mozilla
Firefox delivers safe, easy web browsing.
Package Information
Get detailed information about installed packages:
List Installed Packages
$ apt list --installed
Listing... Done
adduser/jammy,jammy 3.118ubuntu5 all
apt/jammy,jammy 2.4.8 amd64
base-files/jammy,jammy 12ubuntu4.5 amd64
bash/jammy,jammy 5.1-6ubuntu1 amd64
Package Details
$ apt policy firefox
firefox:
Installed: 120.0-1build1
Candidate: 120.0-1build1
Version table:
***120.0-1build1 500
500 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
119.0.1-1build1 500
500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages
Advanced APT Operations
Master these advanced APT commands for better package management:
Full System Upgrade
Upgrade packages and install new dependencies:
$ sudo apt full-upgrade
Reading package lists... Done
Calculating upgrade... Done
The following packages will be upgraded:
linux-headers-generic linux-image-generic
The following NEW packages will be installed:
linux-headers-5.15.0-78-generic linux-image-5.15.0-78-generic
Remove Configuration Files
Completely remove packages including configuration:
$ sudo apt purge git
Reading package lists... Done
The following packages will be REMOVED:
git* git-man* libgit2-34*
Purging configuration files for git (120.0-1build1) ...
Clean Up
Remove cached package files to free disk space:
$ sudo apt autoremove
Reading package lists... Done
The following packages will be REMOVED:
liberror-perl-perl libx11-6
$ sudo apt autoclean
Reading package lists... Done
Del /var/cache/apt/archives/*.deb files
Managing Repositories
APT uses repositories to find packages. Ubuntu includes several by default:
Default Repositories
- Main: Officially supported open-source software
- Universe: Community-maintained software
- Restricted: Proprietary drivers and firmware
- Multiverse: Software restricted by copyright/patents
Adding Repositories
Add third-party repositories for additional software:
# Add PPA (Personal Package Archive)
$ sudo add-apt-repository ppa:deadsnakes/ppa
# Add repository manually
$ sudo add-apt-repository "deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian jammy contrib"
# After adding repositories, always update
$ sudo apt update
Repository Management
# List repositories
$ apt policy
# Remove repository
$ sudo add-apt-repository --remove ppa:deadsnakes/ppa
# View repository sources
$ cat /etc/apt/sources.list
$ ls /etc/apt/sources.list.d/
Package Pinning
Control package versions with pinning:
Hold Packages
Prevent packages from being upgraded:
# Hold a package
$ sudo apt-mark hold firefox
# Unhold a package
$ sudo apt-mark unhold firefox
# Show held packages
$ sudo apt-mark showhold
firefox
APT Configuration
Customize APT behavior with configuration files:
Main Configuration
Primary APT configuration is in /etc/apt/apt.conf:
# Example configuration
APT::Get::Assume-Yes "true";
APT::Get::Show-Versions "true";
Acquire::Languages "none";
Repository Sources
Repository definitions are in /etc/apt/sources.list and /etc/apt/sources.list.d/:
# /etc/apt/sources.list example
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted
deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ jammy universe
deb http://archive.ubuntu.com/ubuntu/ jammy-updates universe
APT vs apt-get
Modern APT vs traditional apt-get:
Recommended APT Commands
- apt install instead of
apt-get install
- apt remove instead of
apt-get remove
- apt upgrade instead of
apt-get upgrade
- apt full-upgrade instead of
apt-get dist-upgrade
Why Use apt?
- Better progress reporting
- Colored output
- More informative package information
- Integrated search functionality
Common APT Tasks
Real-world APT usage scenarios:
Installing Development Tools
# Install common development packages
$ sudo apt install build-essential git python3 nodejs npm
# Install LAMP stack
$ sudo apt install apache2 mysql-server php libapache2-mod-php
System Maintenance
# Regular maintenance routine
$ sudo apt update
$ sudo apt upgrade
$ sudo apt autoremove
$ sudo apt autoclean
Troubleshooting
# Fix broken packages
$ sudo apt --fix-broken install
# Reconfigure packages
$ sudo dpkg-reconfigure package-name
# Check package integrity
$ sudo apt check
Security Considerations
Keep your system secure with APT:
Verify Package Signatures
APT automatically verifies package signatures:
# Check repository keys
$ apt-key list
# Add repository key
$ sudo apt-key add keyfile.asc
Security Updates
# Install security updates only
$ sudo apt install unattended-upgrades
$ sudo dpkg-reconfigure -plow unattended-upgrades
# Check for security updates
$ sudo apt list --upgradable | grep -i security
Practice Exercises
Exercise 1: Basic Package Management
- Update package lists
- Search for a text editor
- Install the text editor
- Check installed version
- Remove the text editor
Click for solution
$ sudo apt update
$ apt search text editor
$ sudo apt install nano
$ apt policy nano
$ sudo apt remove nano
Exercise 2: System Maintenance
- Perform full system upgrade
- Remove unnecessary packages
- Clean package cache
- Add a PPA repository
- Install software from the PPA
Click for solution
$ sudo apt update
$ sudo apt full-upgrade
$ sudo apt autoremove
$ sudo apt autoclean
$ sudo add-apt-repository ppa:libreoffice/ppa
$ sudo apt update
$ sudo apt install libreoffice
What's Next?
Now that you understand APT, let's explore Flatpak, which provides universal application deployment across different Linux distributions!
Key Takeaways
- APT is Ubuntu's traditional package management system
- Always run
apt update before installing software
- Use
apt upgrade for regular system updates
- APT handles dependencies automatically
- Repositories provide trusted, signed packages
- Modern
apt is preferred over apt-get