Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

LX
Linux
0/11 completed
Beginner
The Linux file systemUsers, groups and permissionsPackage managers
Intermediate
Processes and signalsDisks, storage and archivesNetworking commandsSSH and remote access
Advanced
systemd and servicesLogs and troubleshooting
Pro
Securing a serverPerformance and resource limits
Tracks / Linux / Beginner

Package managers

On Linux you rarely download installers from websites. You ask the package manager for software by name, and it downloads it from the distribution's trusted repositories, installs everything it depends on, and keeps it all updated. One command updates every program on the machine.

Which one does my system use?

It depends on the distribution family:

Family Distributions Package manager Package format
Debian Ubuntu, Debian, Linux Mint apt .deb
Red Hat RHEL, Fedora, Rocky, AlmaLinux, Amazon Linux dnf (older: yum) .rpm
Alpine Alpine (tiny, popular in Docker images) apk .apk
Arch Arch, Manjaro pacman .pkg.tar.zst
bash
grep -E "^(NAME|VERSION|ID_LIKE)=" /etc/os-release
command -v apt dnf apk pacman
Output
NAME="Ubuntu"
VERSION="24.04.5 LTS (Noble Numbat)"
ID_LIKE=debian
/usr/bin/apt

This lesson uses apt, the most common on servers; the others work the same way with different words (there's a table at the end).

Updating the package list

apt keeps a local list of every available package. Refresh it before installing anything:

bash
sudo apt-get update 2>&1 | tail -1
Output
Reading package lists...

apt update only downloads the list; it doesn't change any software.

Searching and inspecting

bash
apt-cache search --names-only "^htop$"
apt-cache policy htop | head -3
apt-cache depends jq | grep Depends
Output
htop - interactive processes viewer
htop:
  Installed: (none)
  Candidate: 3.3.0-4build1
  Depends: libc6
  Depends: libjq1

policy shows the installed and available versions; depends shows what else a package needs.

Installing and removing

bash
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y htop > /dev/null 2>&1
command -v htop
dpkg -s htop | grep -E "^(Status|Version)"
dpkg -L htop | grep bin/
Output
/usr/bin/htop
Status: install ok installed
Version: 3.3.0-4build1
/usr/bin/htop
Command Does
sudo apt install nginx Install (and its dependencies). Add -y to skip the "Do you want to continue?" question in scripts
sudo apt remove nginx Remove the program, keep its config files
sudo apt purge nginx Remove it and its config
sudo apt autoremove Remove dependencies nothing needs any more
apt list --installed Everything installed
dpkg -L pkg Files a package installed
dpkg -S /path/file Which package a file belongs to
bash
dpkg -S /usr/bin/curl
apt list --installed 2>/dev/null | wc -l
Output
curl: /usr/bin/curl
244

💡 apt is the friendly command for humans. In scripts and Dockerfiles, use apt-get and apt-cache: their output format is stable, and apt prints a warning when used in scripts.

Upgrading

bash
sudo apt update && sudo apt upgrade        # upgrade everything that's installed
sudo apt full-upgrade                      # also allow removing packages to complete upgrades
sudo apt install --only-upgrade openssl    # upgrade one package

On servers, security updates are so important that Ubuntu can install them automatically:

bash
sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades

When the kernel or a core library is updated, the change only takes effect after a reboot. Ubuntu creates /var/run/reboot-required to tell you so.

Where packages come from

Repositories are listed in /etc/apt/sources.list.d/. Every package is signed, and apt refuses packages whose signature doesn't match a trusted key:

bash
ls /etc/apt/sources.list.d/
grep -E "^(URIs|Suites|Components):" /etc/apt/sources.list.d/ubuntu.sources | head -3
Output
ubuntu.sources
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse

Ubuntu's components are main (supported by Canonical), universe (community-maintained), restricted and multiverse (non-free licences).

Adding a vendor's repository

The versions in your distribution's repository can be a year or two old. For newer versions of tools like Docker, Node.js or PostgreSQL, vendors publish their own repositories. The steps are always the same: download their signing key, add their repository, update, install. For example, Docker's official instructions:

bash
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
  https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
  | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update && sudo apt install docker-ce

⚠️ Adding a repository means trusting that vendor with root access to your machine: their packages install as root. Only add repositories from the official vendor's documentation. Be very careful with curl … | sudo bash installers for the same reason. Read the script first.

Installing a single .deb file

bash
sudo apt install ./some-tool_1.2.3_amd64.deb    # the ./ makes apt treat it as a file and fetch dependencies

Other ways to install software

Method Example Notes
Snap sudo snap install code --classic Ubuntu's sandboxed app packages; auto-updating
Flatpak flatpak install flathub org.gimp.GIMP Desktop apps on any distribution
Language package managers pip, npm, cargo, go install For libraries and developer tools. Use them per project or per user, not with sudo
Static binaries Download into /usr/local/bin Common for Go tools like kubectl and terraform
Docker docker run postgres:18 Run software without installing it on the host at all

The same tasks, other distributions

Task apt (Ubuntu) dnf (RHEL/Fedora) apk (Alpine)
Refresh the list apt update dnf check-update apk update
Install apt install nginx dnf install nginx apk add nginx
Remove apt remove nginx dnf remove nginx apk del nginx
Upgrade all apt upgrade dnf upgrade apk upgrade
Search apt search word dnf search word apk search word
Which package owns a file dpkg -S /usr/bin/x rpm -qf /usr/bin/x apk info --who-owns /usr/bin/x

In a Dockerfile, install and clean up in one RUN so the package lists don't bloat the image:

dockerfile
RUN apt-get update \
 && apt-get install -y --no-install-recommends curl ca-certificates \
 && rm -rf /var/lib/apt/lists/*

Practice

  1. Find out which package owns /usr/bin/ssh.
  2. Install tree, run it on your home folder, then remove it with purge and autoremove.
  3. Check whether a newer version of openssl is available with apt-cache policy openssl.
  4. Write the Alpine version of the Dockerfile RUN line above.
✎ Check your understanding

1.What does sudo apt update do?

2.Which command installs a package on Fedora or RHEL?

3.What's the difference between apt remove and apt purge?

4.Why is adding a third-party repository a security decision?

← Users, groups and permissions