Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux apt-get Command

Complete Guide to the Linux apt-get Command

Linux Command Reference Linux Command Reference

apt-get is the core command-line tool for managing software packages in Debian-based Linux distributions such as Debian and Ubuntu.

apt-get It is a front-end tool for Advanced Packaging Tool (APT), used to handle .deb format software packages. It can automatically resolve dependencies between packages, simplifying software management on Linux systems.

Basic Syntax



sudo apt-get [选项] 命令 [包名]

Common options

Main Features

  1. Automated Dependency Handling: automatically download and install required dependency packages
  2. Repository Management: obtain software packages from configured repositories
  3. System Maintenance: supports system upgrades and cleanup
  4. Command-Line Interface: suitable for scripting and automation

Basic apt-get Usage

1. Update the package list

Before installing or upgrading software, it is recommended to update the local package list:



sudo apt-get update

Execution result:

2. Install packages

Install a single package:



sudo apt-get install package_name

Install multiple packages:



sudo apt-get install package1 package2 package3

Example: install the Firefox browser



sudo apt-get install firefox

3. Remove packages

Remove a package but keep its configuration files:



sudo apt-get remove package_name

Completely remove a package and its configuration files:



sudo apt-get purge package_name

4. Upgrade installed packages

Upgrade all upgradable packages:



sudo apt-get upgrade

Upgrade the system (including system upgrades that may require removing old packages):



sudo apt-get dist-upgrade


Advanced apt-get Usage

1. Search for packages



apt-cache search keyword

Example: search for packages related to Python



apt-cache search python

2. View package information



apt-cache show package_name

3. Clean up unused packages

Delete downloaded package files (.deb):



sudo apt-get clean

Delete packages that are no longer needed (automatic cleanup):



sudo apt-get autoclean

4. Fix broken dependencies



sudo apt-get -f install


Common Problem Solutions

1. Dependency problems

When you encounter dependency problems, you can try:



sudo apt-get -f install

sudo apt-get --fix-broken install

2. Repository problems

If the "Unable to locate package" error occurs:

  1. Check the repository configuration /etc/apt/sources.list
  2. Run sudo apt-get update
  3. Confirm the spelling is correct

3. Lock issues

When the "Could not get lock" error occurs:


Best Practices

Update regularly:



sudo apt-get update && sudo apt-get upgrade

Use dist-upgrade with caution: it may remove some packages to resolve complex dependencies

View changes: see what changes will occur before upgrading



sudo apt-get -s upgrade

Keep the system clean: regularly clean up unneeded packages



sudo apt-get autoremove


Summary of key points

Command Description
apt-get update Update the package list
apt-get install Install packages
apt-get remove Remove packages
apt-get purge Completely remove packages
apt-get upgrade Upgrade all upgradable packages
apt-get dist-upgrade Intelligently upgrade the system
apt-get clean Clean up downloaded package files
apt-get autoremove Remove automatically installed packages that are no longer needed

Remember these core commands, and you can efficiently manage a Debian-based Linux system!

Linux Command Reference Linux Command Reference