16 Useful apt Command Examples for Ubuntu/Debian Linux

Introduction

The apt command is a powerful package management tool used to install, update, remove, and manage packages on Ubuntu and Debian Linux systems. It is the most popular package manager for Debian-based systems, and is used by millions of users around the world. In this article, we will discuss 16 useful apt command examples for Ubuntu/Debian Linux. We will cover topics such as installing packages, updating packages, removing packages, and more. We hope this article will help you get the most out of your Ubuntu/Debian Linux system.

16 Useful apt Command Examples for Ubuntu/Debian Linux

1. Update the package list:

sudo apt update

2. Install a package:

sudo apt install

3. Remove a package:

sudo apt remove

4. Search for a package:

sudo apt search

5. Upgrade all packages:

sudo apt upgrade

6. Upgrade a specific package:

sudo apt upgrade

7. List installed packages:

sudo apt list –installed

8. List all available packages:

sudo apt list

9. Show package information:

sudo apt show

10. Download a package without installing it:

sudo apt download

11. Clean up the local repository of downloaded packages:

sudo apt clean

12. Remove packages that are no longer needed:

sudo apt autoremove

13. Reinstall a package:

sudo apt reinstall

14. List packages that are upgradable:

sudo apt list –upgradable

15. List packages that are upgradable with their versions:

sudo apt list –upgradable –all-versions

16. List packages that are upgradable with their versions and dependencies:

sudo apt list –upgradable –all-versions –with-dependencies

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

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.

16 Useful apt Command Examples for Ubuntu/Debian Linux

The apt command is a powerful command-line tool, which works with Ubuntu/Debian to manage the software and packages. It provides a simple and easy-to-use command line interface to manage the software and packages. In this article, we will explain some useful apt command examples for Ubuntu/Debian Linux.

1. Update the System

The apt command can be used to update the system. It will download the package information from all configured sources and update the system’s package list. To update the system, run the following command:

$ sudo apt update

2. Upgrade the System

The apt command can also be used to upgrade the system. It will download and install the available updates for the system. To upgrade the system, run the following command:

$ sudo apt upgrade

3. Install a Package

The apt command can be used to install a package. It will download and install the package and its dependencies. To install a package, run the following command:

$ sudo apt install 

4. Remove a Package

The apt command can also be used to remove a package. It will remove the package and its configuration files. To remove a package, run the following command:

$ sudo apt remove 

5. Search for a Package

The apt command can be used to search for a package. It will search for the package in the configured sources and display the results. To search for a package, run the following command:

$ sudo apt search 

6. Show Package Information

The apt command can also be used to show the information about a package. It will display the package’s description, version, size, and other information. To show the package information, run the following command:

$ sudo apt show 

7. Clean the Cache

The apt command can be used to clean the cache. It will remove the cached packages and other files from the system. To clean the cache, run the following command:

$ sudo apt clean

8. Autoremove Unused Packages

The apt command can also be used to autoremove unused packages. It will remove the packages that were installed as dependencies but are no longer required. To autoremove unused packages, run the following command:

$ sudo apt autoremove

9. Download a Package

The apt command can be used to download a package. It will download the package and its dependencies from the configured sources. To download a package, run the following command:

$ sudo apt download 

10. List Installed Packages

The apt command can also be used to list the installed packages. It will list all the packages that are installed on the system. To list the installed packages, run the following command:

$ sudo apt list --installed

11. List Available Packages

The apt command can be used to list the available packages. It will list all the packages that are available in the configured sources. To list the available packages, run the following command:

$ sudo apt list

12. List Upgradeable Packages

The apt command can also be used to list the upgradeable packages. It will list all the packages that have available updates. To list the upgradeable packages, run the following command:

$ sudo apt list --upgradeable

13. List Dependencies of a Package

The apt command can be used to list the dependencies of a package. It will list all the packages that are required by the specified package. To list the dependencies of a package, run the following command:

$ sudo apt depends 

14. List Packages by Name

The apt command can also be used to list the packages by name. It will list all the packages that match the specified name. To list the packages by name, run the following command:

$ sudo apt list --name-only 

15. List Packages by Status

The apt command can be used to list the packages by status. It will list all the packages that have the specified status. To list the packages by status, run the following command:

$ sudo apt list --status-only 

16. List Packages by Version

The apt command can also be used to list the packages by version. It will list all the packages that match the specified version. To list the packages by version, run the following command:

$ sudo apt list --version-only 
Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?