# APT and .deb Packages

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

**Course:** [Linux Command Line](https://learn.benibix.com/learn/infrastructure-linux)  
**Time:** 11 min

**After this lesson you can:**

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

## 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.

![Three steps from left to right. First, apt update fetches a fresh list of packages from an online store of packages. Second, apt install downloads one .deb box and the boxes it needs. Third, the files are unpacked onto the server. Below, a box marked every day shows unattended upgrades running the same steps for security fixes.](https://learn.benibix.com/diagrams/inf3-apt.svg)

### 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.

**Words in this lesson:** [Advanced Package Tool (APT)](https://learn.benibix.com/term/infrastructure/apt), [Debian Package (.deb)](https://learn.benibix.com/term/infrastructure/debian-package), [Unattended Upgrades](https://learn.benibix.com/term/infrastructure/unattended-upgrades)

**Question:** What does sudo apt update do?

**Answer:** Fetches a fresh list of packages, without installing anything. apt update only gets a fresh copy of the list. apt upgrade is the command that installs the newer versions.

---

Source: https://learn.benibix.com/learn/infrastructure-linux/apt-and-deb-packages
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
