Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
10 Examples of How to Use New Advanced Package Tool (APT) in Ubuntu/Debian
Advanced Package Tool (APT) is the default package management system for Ubuntu and Debian Linux distributions. It provides a powerful command-line interface for installing, updating, removing, and managing software packages. APT simplifies software management by automatically handling dependencies and maintaining package integrity.
Updating the Package Cache
Before installing or updating packages, it's essential to refresh the package cache. The package cache contains information about all available software packages in the configured repositories.
sudo apt update
This command downloads the latest package information from all configured repositories and updates the local package database.
Installing Packages
Installing software packages is straightforward with APT. Use the install command followed by the package name:
sudo apt install package-name
For example, to install the Vim text editor:
sudo apt install vim
APT automatically resolves and installs all required dependencies along with the requested package.
Updating Packages
Keeping your system updated is crucial for security and stability. To upgrade all installed packages to their latest versions:
sudo apt upgrade
For a more comprehensive upgrade that can remove obsolete packages and install new dependencies:
sudo apt full-upgrade
Removing Packages
To remove an installed package while keeping its configuration files:
sudo apt remove package-name
Example removing Vim:
sudo apt remove vim
Purging Packages
To completely remove a package including all its configuration files:
sudo apt purge package-name
Example completely removing Vim:
sudo apt purge vim
Searching for Packages
To search for packages by name or description:
apt search keyword
Example searching for Python-related packages:
apt search python
Viewing Package Information
To display detailed information about a specific package:
apt show package-name
Example viewing Vim package details:
apt show vim
This displays version information, dependencies, description, and other package metadata.
Advanced APT Operations
Installing Multiple Packages
Install multiple packages simultaneously by listing them space-separated:
sudo apt install vim nano git curl
Installing Packages Without Recommended Dependencies
To install only essential dependencies and skip recommended packages:
sudo apt install --no-install-recommends package-name
Removing Unused Dependencies
Clean up orphaned packages that were installed as dependencies but are no longer needed:
sudo apt autoremove
Cleaning Package Cache
Remove downloaded package files to free disk space:
sudo apt autoclean
For more aggressive cleaning, use:
sudo apt clean
Managing Repositories
APT repositories are configured in /etc/apt/sources.list and files in /etc/apt/sources.list.d/. To add a new repository, create a new list file:
echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/docker.list
Add the repository's GPG key for package verification:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Then update the package cache and install from the new repository:
sudo apt update sudo apt install docker-ce
Common APT Commands Summary
| Command | Description |
|---|---|
apt update |
Update package cache |
apt upgrade |
Upgrade installed packages |
apt install pkg |
Install package |
apt remove pkg |
Remove package (keep config) |
apt purge pkg |
Remove package and config |
apt search term |
Search for packages |
apt show pkg |
Display package information |
apt autoremove |
Remove unused dependencies |
Conclusion
APT is an essential tool for managing software on Ubuntu and Debian systems. These commands provide comprehensive package management capabilities, from basic installation and removal to advanced repository management. Mastering APT ensures efficient system maintenance and software management on Debian-based distributions.
