Skip to content

Latest commit

 

History

History
240 lines (150 loc) · 4.48 KB

APT-package.md

File metadata and controls

240 lines (150 loc) · 4.48 KB

Advanced Package Tool (APT)

The Advanced Package Tool (APT) is a high-level package management system used in Debian-based Linux distributions, including Ubuntu, Kali Linux, and Raspberry Pi OS. It provides an easy interface to interact with the dpkg package manager and handles dependency resolution automatically.


Common apt Commands

1. Update the Package List

Before installing or upgrading packages, update the package list:

apt update
  • Fetches the latest package information from the repositories.

2. Upgrade Installed Packages

Upgrade All Installed Packages

To upgrade all installed packages to their latest versions:

apt list --upgradable
apt upgrade -y
  • The -y option automatically accepts prompts.

Perform a Full Upgrade

To perform a full upgrade (includes removing obsolete packages if necessary):

apt full-upgrade -y
  • Similar to apt upgrade, but can handle dependency changes and remove obsolete packages.

Distribution Upgrade

Alternatively, you can upgrade the entire system:

apt dist-upgrade -y
  • Similar to apt full-upgrade; it handles changing dependencies and can remove obsolete packages.

3. Install a Package

To install a package:

apt install package_name -y

Example:

apt install nginx -y

4. Remove a Package

Remove a Package but Keep Configuration Files

apt remove package_name -y

Example:

apt remove nginx -y

Remove a Package and Its Configuration Files

apt remove --purge package_name -y

5. Remove Unused Packages

To remove packages that were automatically installed as dependencies but are no longer needed:

apt autoremove -y

6. Show Package Information

To display detailed information about a package:

apt show package_name

Example:

apt show nginx

7. List Installed Packages

To list all installed packages:

apt list --installed

To count the number of installed packages:

apt list --installed | wc -l

8. Find Dependencies of a Package

apt depends package_name

Examples:

apt depends vlc
apt depends nginx

9. Clean the Package Cache

APT stores downloaded package files (.deb) in /var/cache/apt/archives/. To clean up and remove these cached files:

apt autoclean

10. Reinstall a Package

To reinstall a package without removing its dependencies:

apt reinstall package_name
  • Useful when a package is corrupted or misconfigured.

Fixing Common APT Errors

1. Fix Broken Dependencies

If you encounter issues with broken dependencies:

apt --fix-broken install

2. Force Reconfiguration of Packages

To force reconfiguration of packages that have not been properly configured:

dpkg --configure -a

3. Unlock APT When Another Process Is Using It

If APT is locked by another process and you need to unlock it:

rm /var/lib/dpkg/lock
rm /var/lib/dpkg/lock-frontend
  • Caution: Ensure no other package managers are running before removing lock files.

Managing APT Repositories (/etc/apt/sources.list)

The /etc/apt/sources.list file contains a list of software repositories from which APT fetches packages. You can edit this file to add or modify repositories.

Useful Sources List Generators

Editing the sources.list File

To edit the sources list:

vim /etc/apt/sources.list

Example:

Default Debian 12 (Bookworm) sources.list:

deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware

Fixing Issues with sources.list

  • Verify Debian Version:

    cat /etc/os-release
    
  • Replace placeholders in sources.list with your actual Debian version (e.g., bullseye, buster).

Adding Missing GPG Keys

If you encounter GPG signature errors when updating packages due to missing keys, you can add the missing keys:

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys KEY_ID
  • Replace KEY_ID with the actual key identifier.