How to Use apt-get Commands on Linux
The apt-get command installs, updates, and removes software on Debian-based Linux systems, including Debian and Ubuntu. You use it in a terminal, usually with administrator privileges, and it reports what it will change before proceeding. These steps assume you have a working internet connection and a supported system that uses APT package management.
What You’ll Need
- A Debian-based Linux system with APT available. These commands are not for every Linux distribution; Fedora and Arch, for example, use different package managers.
- Access to a terminal window and an account permitted to run commands with
sudo. On some systems, an administrator may instead use the root account. - An internet connection to refresh package lists or download packages. Offline installation is possible only when the required package files and dependencies are already available.
Step-by-Step
- Open a terminal. Use your desktop’s application menu to find Terminal, or connect to the machine through an authorized shell session. Commands are case-sensitive; type them as shown, without the angle brackets used for placeholders.
- Refresh the package lists. Run
sudo apt-get update, then enter your password if prompted. This downloads current package indexes from the repositories configured on your computer. It does not itself upgrade installed software. Read the output for failed downloads or repository errors; resolve those before relying on the list. - Find a package name if needed. Search the available package indexes with
apt-cache search keyword, replacingkeywordwith a relevant term. For details about a specific package, useapt-cache show package-name. Search results may include libraries or related tools, so check the description before installing. - Install a package. Run
sudo apt-get install package-name, replacing the placeholder with the exact package name. APT displays the packages it plans to install or change and may show the amount of disk space needed. Review this list, then typeYand press Enter to confirm, orNto cancel. Install several packages by listing their names afterinstall. - Upgrade installed packages carefully. First run
sudo apt-get update, then usesudo apt-get upgrade. APT upgrades packages when it can do so without removing installed packages. Review the proposed changes and confirm only if they make sense. For a broader upgrade that may install or remove packages to resolve dependencies, usesudo apt-get dist-upgrade; inspect the removal list especially carefully. The command name is historical and does not mean it automatically changes your distribution release. - Remove software you no longer need. Run
sudo apt-get remove package-nameto uninstall a package while generally leaving its system-wide configuration files in place. To remove the package and its package-managed configuration files, usesudo apt-get purge package-name. Neither command necessarily removes personal files stored in your home folder. Check the confirmation summary before accepting. - Clean up unused dependencies. After removing software, run
sudo apt-get autoremoveto review packages that were installed as dependencies and are no longer required. Confirm only if the proposed removals are appropriate. Usesudo apt-get cleanto clear downloaded package files from APT’s local cache; this does not uninstall software. - Check a command’s options. Run
apt-get --helpfor a short command overview orman apt-getfor the manual. Pressqto exit the manual. The interactiveaptcommand is often convenient for people at a terminal;apt-getremains common in scripts and documented procedures.
Common Mistakes
- Skipping
update. Installing from stale package indexes can produce outdated results or “unable to locate package” errors. Refresh indexes first, especially after adding or changing repositories. - Confusing update and upgrade.
apt-get updaterefreshes information;apt-get upgradeinstalls available upgrades. Running only the first does not update installed programs. - Accepting prompts without reviewing them. Package operations can install dependencies, replace packages, or remove software. Read the proposed changes before confirming, particularly with
dist-upgradeandautoremove. - Using a package name that is actually an application name. Names can differ. Search with
apt-cache searchand check the package description rather than guessing. - Interrupting a package operation. Closing the terminal or shutting down while APT is working can leave package configuration incomplete. Wait for the command to finish unless it is clearly stuck.
Tips
- Run one package-management operation at a time. APT uses a lock to prevent simultaneous changes; do not delete lock files to bypass it.
- Use
sudoonly for commands that change system packages. Search and information commands such asapt-cache searchnormally do not need it. - For a simulation of many install or removal operations, add
--simulate, for exampleapt-get --simulate install package-name. Treat the result as a preview, not a guarantee that later repository state will be identical. - Keep a record of repository changes and avoid adding repositories you do not trust. APT installs software from the configured sources, so those sources affect what can be installed and updated.
- Do not routinely use
-ywhen learning the commands. It automatically answers yes to prompts, removing an important chance to check the proposed changes.
Troubleshooting
If you see “Permission denied” or a message that you must be root, rerun the system-changing command with sudo, if your account is authorized. If sudo is unavailable, ask the system administrator rather than trying to work around permissions.
If APT cannot locate a package, check the spelling and package name, run sudo apt-get update, and review any repository or network errors. The package may not be available for your system version or configured repositories. Do not add an unfamiliar repository just to make a search result appear.
If downloads fail, check that the device is online and that configured repository addresses are reachable. A temporary server problem may clear later; try again after a short wait. If output says a repository has no release file or cannot be authenticated, do not ignore the warning or disable verification. Check the repository configuration and consult the system administrator or the distribution’s documentation.
If APT reports that another process holds the package lock, wait for the other package operation to finish. If it appears stuck, identify the active process or restart the system only when it is safe to do so. Never remove lock files while a package manager may still be running. If an earlier operation was interrupted, try sudo dpkg --configure -a, then sudo apt-get -f install; read the proposed actions before confirming. If errors continue, save the full terminal output and seek help specific to your distribution.
Frequently Asked Questions
What is the difference between apt and apt-get?apt provides a convenient interactive interface, while apt-get is a lower-level command commonly used in scripts and instructions. Both work with APT package management.
Does apt-get update install updates?
No. It refreshes package indexes. Run an upgrade command afterward to install available updates.
Can I cancel an installation?
At the confirmation prompt, type N and press Enter. Once installation is underway, avoid abruptly closing the terminal; let it finish when possible.
Does remove delete my personal files?
It removes the package, not typically personal files in your home directory. Applications may store settings or data in different locations, so check before deleting files manually.
How do I see what a command will change?
Review APT’s confirmation summary before answering, or use --simulate for a preview of many operations.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.