Skip to content
BENIBIX Learn

APT and .deb Packages

Level 3 · Software and services

How apt adds, updates and removes software on Ubuntu. What a .deb file is, and how safety fixes can install themselves each day.

Course contentsLesson 7 of 10

After this lesson you can

  • Install a program with apt
  • Say why apt update comes first
  • Switch on automatic safety fixes

11 mincovers 3 glossary entries

Worth reading first: Root User and sudo

How software gets onto a Linux machine

On Ubuntu, software is added with apt, the advanced package tool. sudo apt install nginx fetches the program, everything it needs, and sets it up, in one line. Each program comes as a package, a single file ending in .deb. apt also updates and removes them. It needs sudo, because it changes system files.

apt works from a list of packages kept online by Ubuntu. apt update fetches a fresh copy of that list. It does not install anything. apt upgrade then installs the newer versions it found. Run update first, or apt works from an old list and misses the latest fixes.

A package often needs other packages to work. apt reads that list too and fetches them all. Remove a program with apt remove, and apt autoremove clears out the helpers nothing needs any more.

A .deb file is a box with the program, its settings and a note of what it needs. Some makers offer a .deb on their own website. sudo apt install ./app.deb puts it in and still fetches the helpers it needs. A .deb from a stranger can do anything to the machine, so only use ones from a maker you trust.

Security fixes come out all the time. Unattended upgrades is a tool that installs them on its own, once a day, with no one logged in. It is switched on by default in Ubuntu server, but only for security fixes. Bigger version changes still wait for you.

Some fixes only take effect after a restart, such as a fix to the core of the system. Ubuntu leaves a note saying a restart is needed. A server can run for months with fixes downloaded but not yet in use.

A common mistake is to install software by copying a long command from a blog. apt checks that each package really came from Ubuntu. A script piped from a website skips that check. When apt has the program, use apt.

console
$ sudo apt update
$ sudo apt install nginx
$ sudo apt upgrade
Fetch the fresh list, install one program, then bring everything else up to date.
Fetch the list, fetch the boxes, unpack them. Unattended upgrades does the same for safety fixes each day.

Worked example

Emma's server gets a fix overnight

On Tuesday, a bad hole is found in a piece of code many programs share. Ubuntu ships a fixed package that evening.

Emma's server has unattended upgrades on. At 6 the next morning it installs the fix by itself. When Emma logs in, a note says one restart is waiting, and she does it at lunch.

The words for this lesson3

Check yourself

What does sudo apt update do?

Finished this lesson?

Marking it complete also marks its 3 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.