How to Use apt Commands in Ubuntu/Debian [16 Examples]

0
61


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
Install Package in Ubuntu
Install a Package in Ubuntu

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
List of Installed Files From a Package
List of Installed Files From a Package

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
Check Dependencies of Package
Check Dependencies of Package

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
Search For a Package
Search For a Package

Alternatively, you can also use the apt-cache command to search for a package in the system package cache based on a given search term such as name or description.

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
Show Package Information
Show Package Information

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
Check Package for Broke Dependencies
Check Package for Broke Dependencies

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
View Missing Dependencies of Package
View Missing Dependencies of Package

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
Check Installed Package Version
Check Installed Package Version

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
Update System Packages in Ubuntu
Update System Packages in Ubuntu

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
Upgrade Ubuntu System
Upgrade Ubuntu System

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
Remove Unwanted Packages in Ubuntu
Remove Unwanted Packages in Ubuntu

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
Clean Package Repository
Clean Package Repository

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
Remove Package with Configuration Files
Remove Package with Configuration Files

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
Install Deb Package in Ubuntu
Install Deb Package in Ubuntu

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
Remove a Package in Ubuntu
Remove a Package in Ubuntu

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
APT Command Help
APT Command 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.



Source link