How to Use apt Commands in Ubuntu/Debian [16 Examples]
One important thing to master under Linux System/Server Administration is package management using different package management tools.
Different Linux distributions install applications in a pre-compiled package containing binary files, configuration files, and information about the application’s dependencies.
Package management tools help System/Server Administrators in many ways such as:
- Downloading and installing software.
- Compile software from source.
- Keeping track of all software installed, updates, and upgrades.
- Handling dependencies.
- and also keeping other information about installed software and many more.
In this guide, we are going to look at the apt command examples, which are most commonly used in Debian-based Linux distributions, such as Ubuntu, to manage software packages.
The apt is a command-line-based package management tool that is used to manage package installation, upgrades, and removal in Debian-based Linux distributions, such as Ubuntu, Linux Mint, and others.
1. Install Package in Ubuntu
To install a package named “glances“, you would use the ‘apt install‘ command which will install a package along with the needed dependencies.
$ sudo apt install glances
2. View Installed Files From a Package
The following ‘apt content‘ command will display a list of files and directories that are installed on your system as part of the specified package called glances.
$ sudo apt content glances
3. Check the Dependencies of a Package in Ubuntu
To view the dependencies of a package you can use the apt depends command, which displays a list of the dependencies of the specified package called glances.
$ sudo apt depends glances
4. Search for a Package in Ubuntu
The apt search command is used to search for packages in the repositories available based on keywords in their names or descriptions.
For example, to search for packages related to the apache2 web server, you would use the following command:
$ sudo apt search apache2
5. Show Information About a Package in Ubuntu
The apt show command is used to display detailed information about a specific package, which includes its version, size, description, dependencies, and other relevant details.
$ sudo apt show firefox
6. Check Package for Any Broken Dependencies
Sometimes during package installation, you may get errors concerning broken package dependencies, to check that you do not have these problems run the command below with the package name.
$ sudo apt check firefox
7. List Missing Dependencies of Package
To view the recommended missing packages for the apache2 package, you can use the apt recommends command as shown.
$ sudo apt recommends apache2
8. Check the Version of Installed Package on Ubuntu
The apt version command allows you to check the installed version and availability of a package in the repositories.
$ sudo apt version firefox
9. Update All Packages On Ubuntu
The apt update command will help you to download a list of packages from different repositories included on your system and updates them when there are new versions of packages and their dependencies.
$ sudo apt update
10. Upgrade Ubuntu System
The apt upgrade command is used to upgrade installed packages on a system to their latest available versions. It retrieves the latest package versions from the repositories and installs them, replacing any older versions that are currently installed.
$ sudo apt upgrade
11. Remove Unused Packages in Ubuntu
The apt autoremove command is used to remove packages that were automatically installed as dependencies but are no longer needed by any other package on your system.
These packages may have been installed in the past to satisfy the dependencies of other packages, but if those dependencies are no longer present, the packages become unnecessary.
$ sudo apt autoremove
12. Clear Apt Cache in Ubuntu
The apt autoclean or apt clean command is used to clean up the local repository cache by removing old package files that are no longer needed.
$ sudo apt autoclean or $ sudo apt clean
13. Completely Remove a Package in Ubuntu
When you run apt with remove, it only removes the package files but configuration files remain on the system. Therefore, you will have to use purge to remove a package and its configuration files.
$ sudo apt purge glances
14. Install Deb Package in Ubuntu
To install a .deb package file, run the command below with the filename as an argument as follows:
$ sudo apt deb atom-amd64.deb
15. Uninstall Packages in Ubuntu
The apt remove command is used to uninstall or remove a specific package from your system.
$ sudo apt remove wget
16. APT Command Help
The apt help command provides a built-in help system that can provide information on how to use various apt commands and their options.
$ apt help
Summary
Remember that good Linux package management can help you avoid breaking your system. There are so many other package management tools that you can use in Linux.
You can share with us what you use and your experience with it. I hope the article is helpful and for any additional information, leave a comment in the comment section.