25 Useful Apt Commands for Ubuntu and Debian Distributions

Apt commands for Ubuntu and Debian

Discover 25 essential apt commands for Ubuntu and Debian distributions to manage packages, perform upgrades, and maintain a clean system. Boost your efficiency and productivity today!

Table of Contents

Introduction

If you’re an Ubuntu or Debian user, you’ve probably encountered apt commands in your terminal. The apt (Advanced Package Tool) is the backbone of package management for both Ubuntu and Debian-based Linux distributions. It helps users install, remove, upgrade, and manage software packages effortlessly.

Whether you’re a beginner or a seasoned system administrator, mastering apt commands can streamline your workflow, saving you time and preventing errors. This blog post will walk you through 25 useful apt commands that can supercharge your productivity and make package management a breeze. From installing software to cleaning up your system, these commands will help you harness the full power of your Ubuntu or Debian system.


25 Useful Apt Commands for Ubuntu and Debian Distributions

1. apt update

This command refreshes the local repository index, ensuring that your package manager is aware of the latest versions of packages and dependencies.

				
					sudo apt update
				
			

Before installing or upgrading any software, it’s important to update the package list. This ensures that you’re working with the most recent version available from the repositories.

2. apt upgrade

This command upgrades all the outdated packages on your system to their latest available versions.

				
					sudo apt upgrade
				
			

Use apt upgrade to ensure your system is running the latest versions of packages. This is ideal for routine maintenance and security updates.

3. apt full-upgrade

Unlike apt upgrade, this command can remove or install new packages to complete the upgrade process, ensuring the system is fully upgraded.

				
					sudo apt full-upgrade
				
			

A full-upgrade is useful when you need to perform a major upgrade that requires removing obsolete packages or installing new dependencies.

Apt commands for Ubuntu and Debian

Photo by admingeek from Infotechys

4. apt install [package_name]

Installs a specific package or application.

				
					sudo apt install chromium-browser
				
			

If you want to install a software package, replace package_name with the name of the software you wish to install. For instance, chromium installs the Chromium browser.

Apt commands for Ubuntu and Debian

Photo by admingeek from Infotechys

5. apt remove [package_name]

Removes a specific package from your system.

				
					sudo apt remove chromium-browser
				
			

This command will remove the package but leave its configuration files intact. If you want to completely remove a package, including configuration files, use apt purge.

6. apt purge [package_name]

Completely removes a package, including configuration files.

				
					sudo apt purge chromium-browser
				
			

This is ideal when you want to uninstall a package completely, leaving no trace of configuration files on your system.

Apt commands for Ubuntu and Debian

Photo by admingeek from Infotechys

7. apt autoremove

Removes unnecessary packages and dependencies that were installed as dependencies but are no longer needed.

				
					sudo apt autoremove
				
			

Over time, your system may accumulate unused libraries or packages. Running this command regularly helps keep your system clean.

8. apt search [package_name]

Searches for a package in the repository.

				
					sudo apt search vlc

				
			

This command allows you to search the package repositories for available packages. It’s a great way to discover new software or check if a package is available for installation.

The apt search command from Ubuntu terminal

Photo by admingeek from Infotechys

9. apt show [package_name]

Provides detailed information about a specific package, including its description, version, and dependencies.

				
					sudo apt show vlc
				
			
				
					Package: vlc
Version: 3.0.20-3build6
Priority: optional
Section: universe/graphics
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Multimedia Maintainers <debian-multimedia@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 200 kB
Provides: mp3-decoder
Depends: vlc-bin (= 3.0.20-3build6), vlc-plugin-base (= 3.0.20-3build6), vlc-plugin-qt (= 3.0.20-3build6), vlc-plugin-video-output (= 3.0.20-3build6)
Recommends: vlc-l10n (= 3.0.20-3build6), vlc-plugin-access-extra (= 3.0.20-3build6), vlc-plugin-notify (= 3.0.20-3build6), vlc-plugin-samba (= 3.0.20-3build6), vlc-plugin-skins2 (= 3.0.20-3build6), vlc-plugin-video-splitter (= 3.0.20-3build6), vlc-
...omitted for brevity...
				
			

Use this to get more information about a package before installation. It provides details such as the package’s version, description, and its dependencies.

10. apt list --installed

Lists all installed packages on your system.

				
					apt list --installed
				
			
				
					Listing... Done
accountsservice/noble,now 23.13.9-2ubuntu6 amd64 [installed,automatic]
acl/noble-updates,now 2.3.2-1build1.1 amd64 [installed,automatic]
adduser/noble,now 3.137ubuntu1 all [installed,automatic]
adwaita-icon-theme/noble,now 46.0-1 all [installed,automatic]
aha/noble,now 0.5.1-3build1 amd64 [installed,automatic]
alsa-base/noble,now 1.0.25+dfsg-0ubuntu7 all [installed,automatic]
alsa-topology-conf/noble,now 1.2.5.1-2 all [installed,automatic]
alsa-ucm-conf/noble-updates,now 1.2.10-1ubuntu5.4 all [installed,automatic]
alsa-utils/noble,now 1.2.9-1ubuntu5 amd64 [installed,automatic]
amd64-microcode/noble-updates,noble-security,now 3.20231019.1ubuntu2.1 amd64 [installed,automatic]
anacron/noble,now 2.3-39ubuntu2 amd64 [installed,automatic]
apg/noble,now 2.2.3.dfsg.1-5build3 amd64 [installed,automatic]
apparmor/noble-updates,now 4.0.1really4.0.1-0ubuntu0.24.04.3 amd64 [installed,automatic]
appmenu-gtk-module-common/noble,now 0.7.6-2.1ubuntu2 all [installed,automatic]
appmenu-gtk3-module/noble,now 0.7.6-2.1ubuntu2 amd64 [installed,automatic]
...omitted for brevity...
				
			

This command provides a comprehensive list of all the installed packages on your system, useful for audits or troubleshooting.

11. apt list --upgradable

				
					apt list --upgradable
				
			
				
					Listing... Done
ldap-utils/noble-updates 2.6.7+dfsg-1~exp1ubuntu8.2 amd64 [upgradable from: 2.6.7+dfsg-1~exp1ubuntu8]
libldap-common/noble-updates 2.6.7+dfsg-1~exp1ubuntu8.2 all [upgradable from: 2.6.7+dfsg-1~exp1ubuntu8]
libldap2/noble-updates 2.6.7+dfsg-1~exp1ubuntu8.2 amd64 [upgradable from: 2.6.7+dfsg-1~exp1ubuntu8]
				
			

Before upgrading, you can check which packages have updates pending. It helps you keep track of what’s out of date on your system.

12. apt download [package_name]

Downloads a package without installing it.

				
					apt download vlc
				
			

This command will download the specified package as a .deb file, which can be transferred and installed on another system if needed.

13. apt-cache search [keyword]

Searches the package cache for a keyword.

				
					apt-cache search image editor
				
			

This command searches through your local package cache, making it easier to find software related to specific keywords.

14. apt-cache show [package_name]

Displays information about a package, including its version, description, and dependencies.

				
					apt-cache show vlc
				
			

This is similar to apt show but provides the information from the local cache, making it quicker.

The apt-cache show command from the Ubuntu Desktop terminal

Photo by admingeek from Infotechys

15. apt-cache depends [package_name]

Purpose: Displays the dependencies of a package.

				
					apt-cache depends vlc
				
			
				
					vlc
  Depends: vlc-bin
  Depends: vlc-plugin-base
  Depends: vlc-plugin-qt
  Depends: vlc-plugin-video-output
  Recommends: vlc-l10n
  Recommends: vlc-plugin-access-extra
  Recommends: vlc-plugin-notify
  Recommends: vlc-plugin-samba
  Recommends: vlc-plugin-skins2
  Recommends: vlc-plugin-video-splitter
  Recommends: vlc-plugin-visualization
  Suggests: vlc-plugin-fluidsynth
  Suggests: vlc-plugin-jack
  Suggests: vlc-plugin-pipewire
  Suggests: vlc-plugin-svg
				
			

This command is helpful for understanding which packages and libraries a particular software package depends on.

16. apt-cache rdepends [package_name]

Displays a list of packages that depend on a specific package.

				
					apt-cache rdepends vlc
				
			

Use this command to find out what other packages require the package you are interested in.

17. apt-mark hold [package_name]

Prevents a package from being upgraded.

				
					sudo apt-mark hold firefox
				
			

This command is useful when you want to stop a package from being upgraded automatically, especially if a new version introduces issues.

18. apt-mark unhold [package_name]

Reverses the hold, allowing the package to be upgraded again.

				
					sudo apt-mark unhold firefox
				
			

This is used after you’ve previously held a package and now want it to be upgradable again.

19. apt-get dist-upgrade

Upgrades the system by installing new packages and removing obsolete ones.

				
					sudo apt-get dist-upgrade
				
			

While apt full-upgrade does a similar job, apt-get dist-upgrade is more commonly used in Debian-based systems. It’s effective for upgrading the entire system.

20. apt clean

Clears out the local repository of retrieved package files.

				
					sudo apt clean
				
			

This command deletes all cached package files, freeing up space in your system. Use it when your cache becomes too large.

21. apt autoclean

Removes outdated package files from the cache.

				
					sudo apt autoclean
				
			

Unlike apt clean, this command only removes the older versions of packages that are no longer installable.

22. apt-get check

Checks the system for broken dependencies and packages.

				
					sudo apt-get check
				
			

Use this command to diagnose issues with package dependencies or corrupted installations.

23. apt-key adv --keyserver [server] --recv-keys [key_id]

Adds a public key for package authentication.

				
					sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0x12345678
				
			

If you’re using third-party repositories, this command is useful to ensure that your system can authenticate packages from that repository.

24. apt-get source [package_name]

Downloads the source code of a package.

				
					sudo apt-get source vlc
				
			
				
					Reading package lists... Done
E: You must put some 'deb-src' URIs in your sources.list
				
			

Use this command to download the source code of a package for compiling or inspecting it.


Note: To enable the necessary package repositories for downloading, you will need to update your sources.list file and uncomment the deb-src entries.

25. apt-get upgrade --with-new-pkgs

Upgrades the system and installs new packages that are required by upgrades.

				
					sudo apt-get upgrade --with-new-pkgs
				
			
				
					Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
...
				
			

This command allows you to install new packages that might be required during an upgrade, providing a more complete system upgrade.


Conclusion

Mastering the apt command suite is essential for every Ubuntu or Debian user. From installing and upgrading software to cleaning up your system, these 25 commands will help you become more efficient and in control of your Linux environment.

As you grow more comfortable using the command line, these commands will enable you to take full advantage of Ubuntu and Debian’s package management system, keeping your system clean, secure, and optimized.

Did you find this article useful? Your feedback is invaluable to us! Please feel free to share this post!


Related Posts
30 Essential PostgreSQL Commands
Commands
30 Essential PostgreSQL Commands

Discover 30 essential PostgreSQL commands to enhance your database management skills. This comprehensive guide covers key commands, examples, and tips for efficient PostgreSQL use. Perfect

Read More »

Leave a Reply

Your email address will not be published. Required fields are marked *