administration package management in Linux deb, Ubuntu

System Administration

Debian & Ubuntu
Package Management

Basic package management on Debian and Ubuntu Linux. A practical guide to using APT and DPKG for installing, updating, and managing .deb packages.

APT
DPKG
Debian
Ubuntu

This guide applies to Debian, Ubuntu, Linux Mint, Pop!_OS and other Debian/Ubuntu-based distributions using APT and DEB packages.

Linux distributions based on Debian use .deb packages. The low-level package tool is dpkg, while the normal user-facing package manager is apt.

In practical use:

apt = recommended for normal interactive package management
apt-get = recommended for scripts and automation
dpkg = lower-level tool for local .deb files and package database operations

Information & Search

Querying Packages

1. Piping commands together

In the terminal, commands can be combined with the pipe character: |

A pipe sends the output of one command into another command. This is useful when you want to filter or process long command output.

Example:

dpkg -l | grep zip

This command lists packages known to dpkg and filters only lines containing the word zip. However, this can also match package names, descriptions or related text.

For a cleaner package-name search, use:

apt list –installed ‘*zip*’

2. Check whether a package is installed

Check whether a package is installed using apt:

apt list –installed package-name

# Example:
apt list –installed zip

Check package status using dpkg:

dpkg -s package-name

# Example:
dpkg -s zip

Search installed packages with dpkg and dpkg-query:

dpkg -l | grep zip
dpkg-query -l ‘*zip*’

3. List installed packages

List installed packages using apt:

apt list –installed

List packages known to dpkg:

dpkg -l

List only package names of installed packages:

dpkg-query -f ‘${binary:Package}\n’ -W

4. Search for packages in repositories

Search for an available package:

apt search package-name

# Example:
apt search zip

Show detailed package information:

apt show package-name

# Example:
apt show zip

Installation

Updates & Installing Packages

5. Update package information

Before installing or upgrading packages, update the local package index:

sudo apt update

This does not upgrade packages by itself. It only refreshes information about available packages and versions from the configured repositories.

6. Upgrade installed packages

Upgrade installed packages:

sudo apt upgrade

Show packages that can be upgraded:

apt list –upgradable

For a more complete upgrade that may install new dependencies or remove conflicting packages when required:

sudo apt full-upgrade

Use full-upgrade carefully on servers and production systems. Always read the list of packages that will be removed or changed before confirming.

7. Install a package from repositories

Install a package from the configured repositories:

sudo apt install package-name

# Example:
sudo apt install zip

Install multiple packages at once:

sudo apt install zip unzip p7zip-full

8. Install a local .deb file

To install a local Debian package file:

sudo apt install ./package-file.deb

This is usually better than using dpkg directly, because apt can also resolve and install missing dependencies from repositories when possible.

The lower-level dpkg method is:

sudo dpkg –install package-file.deb

# Short form:
sudo dpkg -i package-file.deb

If dpkg reports missing dependencies, repair the installation with:

sudo apt –fix-broken install

Maintenance

Removal & Cleanup

9. Remove a package

Remove an installed package but keep its system configuration files:

sudo apt remove package-name

# Example:
sudo apt remove zip

# Remove multiple packages:
sudo apt remove package1 package2 package3

10. Purge a package completely

Remove a package including its system configuration files:

sudo apt purge package-name

# Alternative form:
sudo apt remove –purge package-name

Important: purge removes package configuration files from system locations such as /etc. It does not normally remove user data stored in home directories.

11. Remove unused dependencies

After removing packages, some automatically installed dependencies may no longer be needed. Remove them with:

sudo apt autoremove

Remove unused dependencies and purge their configuration files:

sudo apt autoremove –purge

Always read the list of packages before confirming.

12. Clean downloaded package cache

APT stores downloaded package files in its cache. To remove old downloaded package files that can no longer be downloaded:

sudo apt autoclean

To clear the local package cache more aggressively:

sudo apt clean

13. Remove a package with dpkg

The lower-level dpkg removal command is:

sudo dpkg –remove package-name

# Short form:
sudo dpkg -r package-name

This removes the package files but usually keeps configuration files.

To purge a package with dpkg:

sudo dpkg –purge package-name

Use dpkg directly only when you know why apt is not the right tool for the job.

Advanced Tools

Inspection, Reinstall & Logs

14. Reinstall a package

Reinstall a package from repositories:

sudo apt reinstall package-name

# Example:
sudo apt reinstall zip

17. Hold a package version

Prevent a package from being automatically upgraded:

sudo apt-mark hold package-name

Remove the hold & Show held packages:

sudo apt-mark unhold package-name
apt-mark showhold

15. Find which package owns a file

If a file exists on the system and you want to know which package installed it:

dpkg -S /path/to/file

# Example:
dpkg -S /usr/bin/zip

16. List files installed by a package

Show files installed by a package:

dpkg -L package-name

# Example:
dpkg -L zip

18. Check package manager logs

APT history log & terminal output log:

less /var/log/apt/history.log
less /var/log/apt/term.log

dpkg log:

less /var/log/dpkg.log

Conclusion

19. Useful command summary

sudo apt update
sudo apt upgrade
apt list –upgradable
apt search package-name
apt show package-name
apt list –installed
apt list –installed package-name
sudo apt install package-name
sudo apt install ./package-file.deb
sudo apt remove package-name
sudo apt purge package-name
sudo apt autoremove
sudo apt autoremove –purge
sudo apt clean
sudo apt autoclean
dpkg -l
dpkg -s package-name
dpkg -L package-name
dpkg -S /path/to/file
sudo dpkg -i package-file.deb
sudo apt –fix-broken install
sudo dpkg -r package-name
sudo dpkg –purge package-name
Practical recommendation: For normal Debian and Ubuntu package management, use apt. Use dpkg mainly for local .deb files, package inspection or recovery tasks. Use apt-get when writing scripts or automated installation procedures.

Komentáře jsou uzavřeny.