System Administration · #11 of 19

Package Management

apt & Software Installation

What is a Package Manager?

A package manager is like an app store for the command line:

Ubuntu uses APT (Advanced Package Tool).


The apt Command

Updating Package Lists

sudo apt update             # Refresh available packages
# This doesn't install anything — just updates the catalog

Upgrading Installed Packages

sudo apt upgrade            # Upgrade all packages
sudo apt full-upgrade       # Upgrade, including removals if needed

Installing Software

sudo apt install firefox    # Install Firefox
sudo apt install vim git    # Install multiple packages
sudo apt install ./package.deb  # Install local .deb file

Removing Software

sudo apt remove firefox     # Remove package (keep config)
sudo apt purge firefox      # Remove package AND config files
sudo apt autoremove         # Remove unused dependencies

Finding Packages

apt search "text editor"    # Search by keywords
apt search ^vim             # Packages starting with 'vim'

Package Information

apt show vim                # Details about a package
apt list --installed        # All installed packages
apt list --upgradable       # Packages with updates available

Check if Installed

dpkg -l | grep vim          # Search installed packages
which vim                   # Find where it's installed

Repository Management

Packages come from repositories (repos). Ubuntu has:

Adding Repositories

# Add a PPA (Personal Package Archive)
sudo add-apt-repository ppa:user/repo
sudo apt update

# Add third-party repo manually
sudo add-apt-repository "deb http://example.com/repo stable main"

Repository Configuration

cat /etc/apt/sources.list              # Main sources
ls /etc/apt/sources.list.d/            # Additional sources

Common Tasks

Update Everything

sudo apt update && sudo apt upgrade -y

Clean Up

sudo apt autoremove                    # Remove orphaned packages
sudo apt clean                         # Clear package cache

Fix Broken Packages

sudo apt --fix-broken install
sudo dpkg --configure -a

dpkg — Low-Level Tool

APT uses dpkg under the hood:

dpkg -l                     # List all installed packages
dpkg -i package.deb         # Install a .deb file
dpkg -r package             # Remove a package
dpkg -L vim                 # List files installed by vim
dpkg -S /usr/bin/vim        # Which package owns this file?

Other Package Formats

Snap

snap find vlc               # Search
snap install vlc            # Install
snap list                   # List installed snaps
snap remove vlc             # Remove

Flatpak

flatpak search gimp         # Search
flatpak install flathub org.gimp.GIMP   # Install
flatpak list                # List installed
flatpak uninstall org.gimp.GIMP         # Remove

Try It!

Practice package management in the terminal:

Exercises:

  1. Update package lists: apt update (simulated)
  2. Search for packages: apt search editor
  3. Show package info: apt show vim
  4. Install a package: apt install htop
  5. List installed: apt list --installed

Try it in the terminal

A sandboxed shell with this lesson’s commands. Type help to see what’s available.

bash — try it