Skip to content

Latest commit

 

History

History
167 lines (147 loc) · 3.83 KB

Advance-Package-Tool-(APT).md

File metadata and controls

167 lines (147 loc) · 3.83 KB

Advanced Package Tool (APT)

Overview

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, always update the package list:

apt update

This fetches the latest package information from the repositories.

2. Upgrade Installed Packages

To upgrade all installed packages to their latest versions:

apt list --upgradable
apt upgrade -y

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

apt full-upgrade -y

To upgrade the entire system while handling dependency changes and removing obsolete packages:

apt dist-upgrade -y

3. Install a Package

To install a package:

apt install package_name

Example:

apt install nginx

4. Remove a Package

To remove a package but keep its configuration files:

apt remove package_name

Example:

apt remove nginx

To completely remove a package along with its configuration files:

apt purge package_name

Example:

apt purge nginx

5. Search for a Package

If you don't know the exact package name, you can search for it:

apt search package_name

Example:

apt search nginx

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

To count the installed packages:

apt list | wc -l

To list only installed packages:

apt list --installed

To count installed packages:

apt list --installed | wc -l

8. Find Dependencies of a Package

To check dependencies of a package:

apt depends package_name

Examples:

apt depends vlc
apt depends nginx

9. Remove Unused Packages

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

apt autoremove -y

10. Clean Up Package Cache

APT caches downloaded package files in /var/cache/apt/archives/. To clear them and free up space:

apt clean

To remove only outdated package files:

apt autoclean

11. Reinstall a Package

To reinstall a package without removing its dependencies (useful for fixing corrupted or misconfigured packages):

apt reinstall package_name

Example:

apt reinstall nginx

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

Overview

The /etc/apt/sources.list file contains a list of software repositories from which APT fetches packages. It can be edited 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

Ensure the correct Debian version is in /etc/os-release:

cat /etc/os-release

Replace bookworm with the correct version (e.g., bullseye, buster) in sources.list.

If GPG Signature Errors Appear

Add missing keys:

apt install debian-archive-keyring