LinuxCommandLibrary

adb-shell-pm

Manage Android packages

TLDR

List installed packages

$ adb shell pm list packages
copy

Install an app package from a given path
$ adb shell pm install /[path/to/app].apk
copy

Uninstall a package from the device
$ adb shell pm uninstall [package]
copy

Clear all app data for a package
$ adb shell pm clear [package]
copy

Enable a package or component
$ adb shell pm enable [package_or_class]
copy

Disable a package or component
$ adb shell pm disable-user [package_or_class]
copy

Grant a permission for an app
$ adb shell pm grant [package] [android.permission.CAMERA|android.permission.ACCESS_FINE_LOCATION|android.permission.READ_CONTACTS|...]
copy

Revoke a permission for an app
$ adb shell pm revoke [package] [android.permission.CAMERA|android.permission.ACCESS_FINE_LOCATION|android.permission.READ_CONTACTS|...]
copy

SYNOPSIS

adb shell pm <subcommand> [options] [arguments]

PARAMETERS

list [-3 -f -d -e -i -s -u --user USER_ID] [FILTER]
    Lists packages: system(-s), enabled(-e), disabled(-d), third-party(-3), with paths(-f), installer(-i), uninstalled(-u)

path PACKAGE
    Prints APK path for given package

install [-r -t -g -d -a -p -f -D -l -s -u --incremental] PACKAGE
    Installs APK: replace(-r), test(-t), grant all perms(-g), downgrade(-d), all users(-a), partial(-p), force(-f), etc.

uninstall [-k] PACKAGE
    Uninstalls package, keep data/cache(-k)

clear PACKAGE
    Clears all data for app

enable PACKAGE_OR_COMPONENT [--user USER_ID]
    Enables package or component

disable [-user USER_ID] PACKAGE_OR_COMPONENT
    Disables package or component

grant PACKAGE permission
    Grants runtime permission to package

revoke PACKAGE permission
    Revokes runtime permission from package

dump PACKAGE_OR_UID
    Dumps detailed package info

set-installer PACKAGE installer
    Sets package installer package name

get-install-location
    Returns current install location

DESCRIPTION

The adb shell pm command invokes the Android Package Manager (pm) on a connected Android device through the Android Debug Bridge (ADB). ADB is a versatile command-line tool from the Android SDK that facilitates communication between a host computer and Android devices or emulators.

Package Manager handles core operations on apps and components, including installing APKs, uninstalling packages, listing installed apps, clearing app data, enabling/disabling packages or components, granting/revoking permissions, and querying package details. It is indispensable for developers, testers, and power users managing apps programmatically without relying on the device's GUI.

Usage requires USB debugging enabled on the device, ADB installed on the host (Linux, macOS, Windows), and a connected device via USB or TCP/IP. Commands execute in the device's shell environment, respecting user permissions and system policies. Many operations require no root access, but some advanced features like moving apps to external storage may need elevated privileges.

Common workflows include bulk package management, debugging app states, preparing devices for testing, or scripting deployments. Output is typically concise, with options for filtering and formatting.

CAVEATS

Requires ADB setup, USB debugging enabled, and authorized device. Some commands fail without shell root. Not for production; use cautiously to avoid data loss. Android version affects option availability.

EXAMPLES

List all packages:
adb shell pm list packages

Install APK:
adb shell pm install /sdcard/app.apk

Clear app data:
adb shell pm clear com.example.app

REQUIREMENTS

Android SDK platform-tools installed. Run adb devices to verify connection.

HISTORY

Introduced with Android 1.0 (2008) as part of AOSP platform-tools. Evolved with Android features like multi-user support (Android 4.2), permissions model (Android 6.0), and scoped storage (Android 10+). ADB/pm remain core developer tools.

SEE ALSO

adb(1)

Copied to clipboard