DevOps

Essential APT Commands Every Ubuntu User Should Know

APT (Advanced Package Tool) commands 
APT is used in Debian/Ubuntu-based systems (like Ubuntu, Linux Mint, etc.) to manage software packages (install, update, remove, etc.).

Let’s go step by step :

Basic APT Commands Explained

CommandDescriptionExample
apt search <package_name>Searches for a package in the repositories.apt search python3
apt install <package_name>Installs a package.sudo apt install git
apt remove <package_name>Removes the package, but keeps config files.sudo apt remove firefox
apt purge <package_name>Removes the package and its config files completely.sudo apt purge firefox
apt autoremoveRemoves unnecessary dependencies (packages installed automatically but no longer needed).sudo apt autoremove
apt updateUpdates the local package index (list of available packages).sudo apt update
apt upgradeUpgrades all installed packages to the latest version.sudo apt upgrade
apt list --upgradableLists all packages that can be upgraded.apt list --upgradable
apt show <package_name>Shows detailed information about a package.apt show nginx

 

More Useful APT Commands

CommandDescriptionExample
apt-get cleanClears out the local repository of downloaded package files.sudo apt-get clean
apt-get autocleanRemoves only old versions of downloaded packages.sudo apt-get autoclean
apt-cache search <package>Searches for a package (older method, but still useful).apt-cache search mysql
apt-cache show <package>Shows information about a package.apt-cache show vim
apt policy <package>Shows installed version and available version.apt policy python3
apt-mark hold <package>Prevents a package from being upgraded.sudo apt-mark hold firefox
apt-mark unhold <package>Allows a package to be upgraded again.sudo apt-mark unhold firefox
apt full-upgradeSimilar to upgrade, but can remove old packages if needed.sudo apt full-upgrade
apt list --installedLists all installed packages.apt list --installed
apt edit-sourcesOpens the sources.list file for editing (where repositories are listed).sudo apt edit-sources
apt depends <package>Shows dependencies required by a package.apt depends nginx
apt rdepends <package>Shows packages that depend on this package.apt rdepends python3

 

System Maintenance Commands (often used with APT)

CommandDescription
sudo dpkg -lLists all installed packages.
sudo dpkg -S <file>Finds which package owns a particular file.
sudo dpkg -i <package.deb>Installs a .deb file manually.
sudo dpkg -r <package>Removes a manually installed package.
sudo dpkg --configure -aFixes broken installations.
sudo apt --fix-broken installRepairs broken dependencies.

 

Recommended Usage Flow (Routine Maintenance)

When maintaining your Ubuntu system:

sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
sudo apt autoclean

This keeps your system clean, up-to-date, and free from unused packages.

 

 


About author

author image

Amrit panta

Fullstack developer, content creator



Scroll to Top