Package managers¶
Practical 2.6 package-managers-annex.pdf · PDF
How did you install the last program on a Windows PC at home? Search the web, pick a link, download an .exe, click Next, Next, Next... and hope it was the real site. And on your phone? Open the store, tap Install. Which one is safer? Which one updates itself?
Linux had the phone's way of installing software in the 1990s — about ten years before the first phone app store. Today you learn the tool behind it, and you find out what apt update and apt upgrade really did on your servers.
What you will learn
- What a package, a repository and a package manager are
- Refresh the catalogue and upgrade a system with
apt updateandapt upgrade - Find, inspect and install a program with
apt search,apt showandapt install - What a dependency is, and how to read it in apt's output
- The difference between
remove,purgeandautoremove— with evidence - Where a loose
.debfile, Flatpak and Snap fit next to apt
Three words¶
A package is one file that contains a program, plus a label with its name, its version and what else it needs. On Debian and Ubuntu, package files end in
.deb.A repository is a warehouse of packages on a server, run by the distribution. Debian 13 has more than 68,000 packages in its main repository.
A package manager is the program that talks to the warehouse: it downloads a package, checks it, installs it, and remembers every file it put on the disk. On Debian and Ubuntu it is apt.
Back in the kitchen: the repository is the wholesale supplier. apt update brings the supplier's new catalogue — nothing is delivered yet. apt install is the order: the van brings the product and every ingredient it needs. The delivery note is signed, so nobody can swap a box on the way.
flowchart LR
subgraph REPO["Repository (the supplier)"]
P["<b>Packages</b><br>.deb files<br>with signed labels"]
end
subgraph VM["deb-lab"]
A["<b>apt</b><br>the person who<br>places the orders"]
D["<b>Disk</b><br>installed programs"]
end
P -->|"apt update: the catalogue"| A
P -->|"apt install: the order + its ingredients"| A
A -->|"installs and remembers each file"| D
A little history¶
Ian Murdock started Debian in August 1993. Its first package tool, dpkg, could install one package file — but the user had to find every needed file by hand. APT fixed that: it shipped with Debian 2.1 on 9 March 1999 and fetched the missing pieces by itself. Almost every Linux distribution has copied the idea since.
Where does your software come from?¶
apt reads the list of warehouses from a file. Look at it on deb-lab:
If that file is empty or missing, newer systems use /etc/apt/sources.list.d/debian.sources. You will find the address deb.debian.org/debian and the release word trixie (also trixie-updates and trixie-security).
Update, search, show, install¶
First, the new catalogue — and what is waiting:
apt update ends with N packages can be upgraded or All packages are up to date. It installed nothing. apt list --upgradable lists each package with its old and new version.
Careful: apt update does not update your programs
It only downloads the new catalogue. The programs change with apt upgrade. Two steps, always in that order.
Now look before you install:
apt show reads the label of the package: Version, Download-Size, and the line Depends, which lists what it needs (libtext-charwidth-perl, perl:any). You have still installed nothing.
Then order two packages:
Read the screen before you answer Y. Under Installing dependencies, apt lists fortunes-min and librecode3. You asked for two packages; four arrive.
A dependency is a package that another package needs in order to work.
fortune-mod is the program; fortunes-min is its list of quotes. apt reads the label, finds what is missing and adds it to the order. Run them:
The bar | passes the text of the first program to the second: a cow says something. dpkg -L lists every file the package put on your disk — the program itself is /usr/games/cowsay.
When apt complains
- Permission denied … are you root? → you forgot
sudo. The message says exactly that. - Unable to locate package → a typing mistake, or you never ran
apt updateon this VM. - Could not get lock /var/lib/dpkg/lock-frontend → another apt is running (the Software app or a second terminal). Wait a minute or close it.
Three ways to take software out¶
| Command | What it removes | What it leaves |
|---|---|---|
apt remove X |
The program files of X | Its system configuration in /etc, and its dependencies |
apt purge X |
The program files and the configuration in /etc |
Its dependencies; your own files in /home |
apt autoremove |
Dependencies that nothing needs any more | Everything you asked for by name |
apt upgrade |
Nothing: it installs newer versions | — |
remove is not purge¶
The editor nano keeps its settings in /etc/nanorc. Prove the difference:
After remove, the file is still there, and the last line of dpkg -l nano starts with rc: removed, configuration kept. That is on purpose — reinstall it and your settings are back.
After purge, ls says No such file or directory. The last line puts nano back: you will need it.
Careful: I removed it, so it is gone?
After remove, the configuration stays on the disk. And neither remove nor purge touches your own files in /home.
The orphans¶
The first command prints The following packages were automatically installed and are no longer required: fortunes-min librecode3. They are orphans: dependencies that nothing needs any more. purge would not take them either. apt autoremove removes exactly those, and nothing you asked for by name.
Upgrade everything, and read the diary¶
apt upgrade shows a summary line (Upgrading: N, Installing: 0, Removing: 0). Afterwards, apt list --upgradable prints only the word Listing...: nothing left.
Who decides which version of Firefox you get? The distribution. Debian stable ships tested versions and then sends only security fixes. That is why deb-lab is "boring" — and why servers love it.
apt also keeps a diary of everything it did:
tail -n 25 shows the last 25 lines of a file. Each block has a Start-Date, the Commandline, the packages under Install:, Remove:, Purge: or Upgrade:, and an End-Date. The packages you did not ask for by name carry the word automatic.
Outside the warehouse: .deb files, Flatpak and Snap¶
A loose .deb¶
Some companies do not put their program in Debian's repository; they offer a .deb file on their web page. Install it with apt and the path to the file, so apt can still fetch the dependencies:
apt download leaves a file like sl_5.02-1+b1_amd64.deb in the current folder. The * means "any text here". The ./ matters: it means "the file in this folder"; without it apt looks for a package named like the file. A train crosses your terminal.
The old tool dpkg -i also installs a file, but stops if a dependency is missing.
A loose .deb runs its install scripts as root
Installing a package gives its scripts full power over the system. Use the repository first; if you need a loose .deb, take it only from the maker's official site.
Two newer formats¶
Why would anyone want another format? To get the newest version of an app, the same package on every distribution, and apps locked in a sandbox — a closed box with limited access to your files.
apt + .deb |
Flatpak | Snap | |
|---|---|---|---|
| Made by | Debian, 1990s | Alexander Larsson and the community; first release 2015 | Canonical (Ubuntu) |
| Warehouse | The distribution's repositories | Flathub (flathub.org) |
Snap Store (snapcraft.io) |
| Dependencies | Shared between all packages | Bundled, on shared runtimes | Bundled in the package |
| Sandbox | No | Yes | Yes |
| Good for | The system and servers | Desktop apps, any distribution | Ubuntu; also server tools |
| Command | apt install vlc |
flatpak install flathub org.videolan.VLC |
snap install vlc |
Ubuntu installs Snap by default; Debian installs neither Flatpak nor Snap by default. One machine can use all three systems side by side.
The other machine¶
On ubu-srv, the same two commands keep it up to date, and one more shows its snaps:
Ubuntu talks to archive.ubuntu.com and security.ubuntu.com, and its release word is resolute. snap list shows the installed snaps, or says none are installed yet.
Key takeaways¶
- A package is a program plus a label; a repository is the warehouse; apt is the package manager that places the orders.
apt updatedownloads the catalogue;apt upgradeinstalls newer versions;apt installbrings a package and its dependencies.removekeeps the configuration (rcindpkg -l);purgedeletes it;autoremovetakes the orphans.- apt records every action in
/var/log/apt/history.log. - Install a loose
.debwithsudo apt install ./file.deb, only from the maker's official site. - Flatpak and Snap bundle their dependencies and run apps in a sandbox, next to apt.
Quick check¶
1. What does sudo apt update do?
- Downloads the new list of packages and installs nothing
- Installs the newest version of every program
- Removes the programs that are no longer used
- Restarts the system to apply pending updates
apt update refreshes the catalogue from the repository. Your programs only change when you run apt upgrade.
2. After sudo apt remove nano, what is still on the disk?
- Its configuration in /etc
- Nothing at all from the package
- The program, but not its settings
- Only a backup copy of the program
remove deletes the program files and keeps the system configuration: dpkg -l shows the package as rc. purge would delete /etc/nanorc too.
3. What is a dependency?
- A package that another package needs to work
- A program that starts when the system boots
- An update that fixes a security problem
- A copy of a package kept as a backup
A dependency is listed on the package's label (Depends). apt reads it and adds the missing packages to the order, like fortunes-min for fortune-mod.
4. You removed fortune-mod. Which command takes out fortunes-min and librecode3, which nothing needs now?
- sudo apt autoremove
- sudo apt purge fortune-mod
- sudo apt upgrade
- sudo apt update
Packages installed automatically as dependencies become orphans when nothing needs them. autoremove removes exactly those; purge only deletes the configuration of the package you name.
5. A company offers its program as app.deb on its official site. What is the correct way to install it?
- sudo apt install ./app.deb
- sudo apt update app.deb
- apt search app.deb
- dpkg -L app.deb
With ./ apt installs the file in this folder and still fetches its dependencies from the repository. Without ./, apt looks for a package with that name in the warehouse.
6. Why does an app installed as a Flatpak have limited access to your files?
- It runs inside a sandbox
- It is installed without sudo
- It shares its dependencies with apt
- It comes from the Debian repository
Flatpak and Snap run apps in a sandbox, a closed box with limited access to the rest of the system. Packages from apt are not sandboxed.
7. A classmate says purge also deletes the dependencies it brought and the files in their home folder. Select the two that are true.
- Orphaned dependencies are removed with apt autoremove, not with purge
- Neither remove nor purge touches your own files in /home
- purge removes every package that was installed on the same day
- purge deletes the whole /home folder of the current user
purge deletes a package's program files and its configuration in /etc. Orphans go with autoremove, and your personal files in /home are never touched by apt.
On Linux, one tool updates the whole system. Windows does it differently — with three doors and one famous Friday in May 2017: Software and updates on Windows.