> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/linux-server-administrator/package-management/debian.md).

# Debian

Debian-based distributions (e.g., **Ubuntu, Kali Linux, Debian**) use **dpkg** (Debian Package Manager) and **APT** (Advanced Package Tool) to install, manage, and remove software packages.

***

## **DPKG (Debian Package Manager)**

**dpkg** is a low-level package manager for Debian-based systems, primarily used for managing `.deb` packages. It does not handle dependencies automatically.

#### **Checking Installed Packages**

List all installed packages:

```bash
dpkg --list
```

Check if a specific package is installed:

```bash
dpkg -l | grep <package>
```

Show details of an installed package:

```bash
dpkg -s <package>
```

List files installed by a package:

```bash
dpkg -L <package>
```

Find which package owns a specific file:

```bash
dpkg -S <file>
```

#### **Installing and Removing Packages**

Install a `.deb` package (does not resolve dependencies):

```bash
dpkg -i <package>.deb
```

Fix broken dependencies after a failed installation:

```bash
apt --fix-broken install
```

Remove an installed package (keeps configuration files):

```bash
dpkg -r <package>
```

Completely remove a package and its configuration files:

```bash
dpkg -P <package>
```

#### **Working with DPKG Database**

Reconfigure a package (useful after installation issues):

```bash
dpkg-reconfigure <package>
```

Forcefully remove a broken package:

```bash
dpkg --remove --force-remove-reinstreq <package>
```

***

## **APT (Advanced Package Tool)**

**APT** is a high-level package manager that **automatically handles dependencies**, making package management easier.

#### **Updating Package Lists**

Update the package list from repositories:

```bash
apt update
```

Upgrade all installed packages to the latest version:

```bash
apt upgrade
```

Perform a full system upgrade (handles package removals if required):

```bash
apt full-upgrade
```

Upgrade a specific package:

```bash
apt install --only-upgrade <package>
```

#### **Installing and Removing Packages**

Install a package and resolve dependencies:

```bash
apt install <package>
```

Remove a package but keep configuration files:

```bash
apt remove <package>
```

Completely remove a package and its configuration files:

```bash
apt purge <package>
```

#### **Finding and Managing Packages**

Search for a package in the repository:

```bash
apt search <package>
```

Show detailed information about a package:

```bash
apt show <package>
```

List all installed packages:

```bash
apt list --installed
```

#### **Cleaning Up Unused Packages**

Remove unneeded dependencies:

```bash
apt autoremove
```

Clear downloaded package archives to free up space:

```bash
apt clean
```

Remove only outdated package archives:

```bash
apt autoclean
```

Show past APT transactions:

```bash
cat /var/log/apt/history.log
```
