Update Package Lists
To update the local package database with the latest available packages from the repositories, use the following command:
sudo apt update
Upgrade Installed Packages:
To upgrade all installed packages to their latest versions, use the following command:
sudo apt upgrade
Install a Package:
To install a package, use the apt install command followed by the package name:
sudo apt install package-name
Remove a Package:
To uninstall a package while keeping its configuration files, use the apt remove command:
sudo apt remove package-name
To completely remove a package, including its configuration files, use:
sudo apt purge package-name
Search for a Package:
You can search for a package using the apt search command. For example:
apt search package-name
List Installed Packages:
To list all installed packages, you can use dpkg and grep together:
dpkg -l | grep ii
Show Package Information:
To display detailed information about a package, use the apt show command:
apt show package-name
List Repositories:
To list the repositories enabled on your system, check the contents of /etc/apt/sources.list and the files in the /etc/apt/sources.list.d/ directory.
Add a Repository:
You can add a software repository to your system using the add-apt-repository command. For example:
sudo add-apt-repository ppa:repository-name
Remove a Repository:
To remove a repository, you can either edit the repository list files in /etc/apt/sources.list.d/ or use the add-apt-repository command with the –remove option.
Autoremove Unused Packages:
To remove packages that were automatically installed to satisfy dependencies but are no longer needed, use the apt autoremove command:
sudo apt autoremove
Check for Broken Packages:
To check for and repair broken packages, use the following command:
sudo apt --fix-broken install
View APT History:
To view the APT history, including installed, upgraded, and removed packages, you can use the apt history command:
apt history
Check for Upgradable Packages:
To see a list of packages that can be upgraded, you can use the apt list –upgradable command:
apt list --upgradable
Search for a File Provided by a Package:
If you’re looking for which package provides a specific file, you can use the apt-file command (you may need to install it and update its database first):
sudo apt install apt-file
sudo apt-file update
apt-file search file-name
Clean APT Cache:
Over time, the APT cache can occupy a significant amount of disk space. You can clean it up using the apt clean command:
sudo apt clean
Download a Package Without Installing:
You can download a package without installing it using the apt-get download command:
sudo apt-get download package-name
Simulate Package Installation:
To simulate the installation of a package without actually installing it, use the apt-get -s install command:
sudo apt-get -s install package-name
Upgrade Distribution to New Release:
To upgrade your Linux distribution to a new release (e.g., from Ubuntu 20.04 to 22.04), use the do-release-upgrade command for Ubuntu:
sudo do-release-upgrade
Search for Packages by Description:
You can search for packages by their descriptions using apt-cache search:
apt-cache search "search term"