Skip to main content

APT Commands

Complete reference for APT package management inside the Ubuntu proot environment. For background on how package managers work, see What is a Package Manager.

โ„น๏ธNo sudo required

When running inside proot-distro, you are already root. All apt commands run directly without sudo. If you are accessing the environment from an outer shell or script that does not enter proot as root, prefix commands with sudo as usual.


Installing Packagesโ€‹

CommandDescriptionExample
apt install <pkg>Install a package and its dependenciesapt install vim
apt install -y <pkg>Install without confirmation promptapt install -y curl wget
apt install <pkg1> <pkg2>Install multiple packages at onceapt install git nodejs npm
apt install --no-install-recommends <pkg>Install without recommended extras (smaller footprint)apt install --no-install-recommends python3
apt install <pkg>=<version>Install a specific versionapt install nodejs=18.19.0-1nodesource1
apt reinstall <pkg>Reinstall a currently installed packageapt reinstall openssh-client
dpkg -i <file>.debInstall a local .deb filedpkg -i package.deb
$apt install -y build-essential
โœ…๐Ÿ’ก Fix broken installs after dpkg

If dpkg -i fails due to missing dependencies, run:

$apt install --fix-broken -y

This resolves and installs any missing dependencies for the partially installed package.


Removing Packagesโ€‹

CommandDescriptionExample
apt remove <pkg>Remove a package but keep its configuration filesapt remove apache2
apt purge <pkg>Remove a package and its configuration filesapt purge apache2
apt remove --purge <pkg>Same as apt purgeapt remove --purge nginx
apt autoremoveRemove packages that were installed as dependencies and are no longer neededapt autoremove
apt autoremove --purgeAutoremove and delete configuration filesapt autoremove --purge
$apt autoremove -y
โš ๏ธPurge is permanent

apt purge deletes configuration files in /etc that belong to the package. If you have customized config files, back them up before purging.


Updating & Upgradingโ€‹

CommandDescriptionExample
apt updateRefresh the package index from repositoriesapt update
apt upgradeUpgrade all installed packages to their latest versions (safe, no removals)apt upgrade -y
apt full-upgradeUpgrade packages, adding or removing dependencies as neededapt full-upgrade -y
apt dist-upgradeSame as full-upgrade; handles changing dependencies intelligentlyapt dist-upgrade -y
โญBest Practice

Always run apt update before apt install or apt upgrade to ensure you are pulling from the latest package index.

$apt update && apt upgrade -y

Searching & Informationโ€‹

CommandDescriptionExample
apt search <term>Search package names and descriptionsapt search image editor
apt show <pkg>Display detailed information about a packageapt show ffmpeg
apt listList all available packagesapt list
apt list --installedList only installed packagesapt list --installed
apt list --upgradableList packages with available upgradesapt list --upgradable
dpkg -lList all installed packages with version and statusdpkg -l
dpkg -l <pattern>Filter installed packages by name patterndpkg -l 'lib*'
dpkg -L <pkg>List all files installed by a packagedpkg -L coreutils
$apt list --installed 2>/dev/null | grep -i python
โœ…๐Ÿ’ก Tip

Pipe dpkg -l or apt list through grep to quickly filter results when searching for a specific package.


Cache Managementโ€‹

CommandDescriptionExample
apt cleanDelete all cached .deb files from /var/cache/apt/archivesapt clean
apt autocleanDelete only cached .deb files that can no longer be downloaded (obsolete)apt autoclean
apt-cache statsShow cache statistics (total packages, versions, dependencies)apt-cache stats
apt-cache policy <pkg>Show installed and candidate versions plus repository priorityapt-cache policy nodejs
$apt clean && apt autoclean
โ„น๏ธNote

In a proot environment, disk space is shared with the Android host. Running apt clean after large installs helps reclaim storage.


Common Flagsโ€‹

FlagLong FormDescription
-y--yesAssume "yes" to all prompts; run non-interactively
--no-install-recommendsSkip recommended (but not required) packages
-f--fix-brokenAttempt to fix broken dependencies
-s--dry-runSimulate the operation without making changes
--allow-downgradesAllow installing an older version of an already-installed package
-q--quietSuppress progress output; useful in scripts
-d--download-onlyDownload packages but do not install them
Combining flags

Flags can be combined in a single command. For example, to do a quiet, non-interactive upgrade without recommended packages:

$apt upgrade -y -q --no-install-recommends

For a dry run before a full upgrade to preview what would change:

$apt full-upgrade --dry-run

Troubleshooting Common Issuesโ€‹

E: Unable to locate package

The package index is out of date or the package name is wrong.

  1. Update the index first:
    $apt update
  2. Verify the package name with apt search.
  3. Check that the correct repositories are enabled in /etc/apt/sources.list.
dpkg was interrupted / broken packages

A previous install was interrupted, leaving the package database in a broken state.

$dpkg --configure -a
$apt install --fix-broken -y
Hash Sum mismatch

The downloaded package does not match the expected checksum, often caused by a stale cache or network issue.

$apt clean
$apt update

If it persists, try switching to a different mirror in /etc/apt/sources.list.

Could not get lock /var/lib/dpkg/lock

Another apt or dpkg process is running. In proot, this can also happen if a previous session crashed.

$rm -f /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/cache/apt/archives/lock
$dpkg --configure -a
โš ๏ธWarning

Only remove lock files if you are certain no other package operation is running.

Held packages preventing upgrade

Some packages are held back and not upgraded. To see which:

$apt-mark showhold

To unhold a package and allow it to upgrade:

$apt-mark unhold <package-name>