I'd like to SSH into my phone, download an APK, and install it remotely. Is there a command available on the phone that would allow me to do this?


wget localhost/file.apk 
android_install file.apk

Need to automate an install, as I just accidentally wiped my SD card and everything on it. :(


In adb shell or terminal emulator (and most likely over SSH) you can use the pm utility to install apps. The command is:

pm install /sdcard/app1.apk

The following are the switches of pm:

usage: pm [list|path|install|uninstall]
       pm list packages [-f] [-d] [-e] [-u] [FILTER]
       pm list permission-groups
       pm list permissions [-g] [-f] [-d] [-u] [GROUP]
       pm list instrumentation [-f] [TARGET-PACKAGE]
       pm list features
       pm list libraries
       pm path PACKAGE
       pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH
       pm uninstall [-k] PACKAGE
       pm clear PACKAGE
       pm enable PACKAGE_OR_COMPONENT
       pm disable PACKAGE_OR_COMPONENT
       pm setInstallLocation [0/auto] [1/internal] [2/external]

The list packages command prints all packages, optionally only
those whose package name contains the text in FILTER.  Options:
  -f: see their associated file.
  -d: filter to include disbled packages.
  -e: filter to include enabled packages.
  -u: also include uninstalled packages.

The list permission-groups command prints all known
permission groups.

The list permissions command prints all known
permissions, optionally only those in GROUP.  Options:
  -g: organize by group.
  -f: print all information.
  -s: short summary.
  -d: only list dangerous permissions.
  -u: list only the permissions users will see.

The list instrumentation command prints all instrumentations,
or only those that target a specified package.  Options:
  -f: see their associated file.

The list features command prints all features of the system.

The path command prints the path to the .apk of a package.

The install command installs a package to the system.  Options:
  -l: install the package with FORWARD_LOCK.
  -r: reinstall an exisiting app, keeping its data.
  -t: allow test .apks to be installed.
  -i: specify the installer package name.
  -s: install package on sdcard.
  -f: install package on internal flash.

The uninstall command removes a package from the system. Options:
  -k: keep the data and cache directories around.
after the package removal.

The clear command deletes all data associated with a package.

The enable and disable commands change the enabled state of
a given package or component (written as "package/class").

The getInstallLocation command gets the current install location
  0 [auto]: Let system decide the best location
  1 [internal]: Install on internal device storage
  2 [external]: Install on external media

The setInstallLocation command changes the default install location
  0 [auto]: Let system decide the best location
  1 [internal]: Install on internal device storage
  2 [external]: Install on external media

For example, you can force the app to install directly to the external storage (Froyo/Gingerbread style.)

P.S. The wget utility should be available via BusyBox on CM7. If not, you can always install it via Android Market.

  • This is exactly what I'm looking for. pm does exist at /system/bin/pm, but unfortunately over SSH (even as root) it doesn't do anything. Running any pm command produces no output. Is there something I'm doing wrong? It does work in terminal emulator, just not over SSH for some reason :( – Naftuli Kay Sep 1 '11 at 14:47
  • I've had PM work as root from adb in CM6; beyond that I am unsure. – Broam Sep 1 '11 at 15:02
  • 1
    May I ask what is the reason you prefer SSH over ADB shell? – Chahk Sep 1 '11 at 15:09
  • 1
    @Chahk: adb only works via the USB cable, doesn't it? And SSH can be over a wireless network. Also, ssh is there everywhere, but adb has to be installed. – imz -- Ivan Zakharyaschev Aug 26 '12 at 9:30
  • Error: java.lang.SecurityException: Permission Denial: runInstallCreate from pm command asks to run as user -1 but is calling from user 11; this requires android.permission.INTERACT_ACROSS_USERS_FULL – user246543 Dec 12 '17 at 2:05

I'd suggest you plug your phone into a pc with the sdk (or at least adb) installed and in debugging mode. After this, write a script that goes through your apps and installs them via adb, e.g. adb install x:\path\to\app1.apk.

  • There's no native utility on the phone to do this? – Naftuli Kay Sep 1 '11 at 4:16
  • 1
    No, since most apps just copy their .apk file to /data/app. You could try copying all your apks there and then rebooting (note that this needs root, but I assume from the cyanogenmod tag that you're rooted). – onik Sep 1 '11 at 4:30
  • Now that is something I can do over SSH, cp * /data/app && reboot – Naftuli Kay Sep 1 '11 at 4:32
  • 1
    note that the cp command is not available in stock Android (i.e. non-custom ROM), so if you're not using Cyanogen you may need to (ab)use the cat command. – Lie Ryan Sep 1 '11 at 6:18
  • 2
    Actually, on the phone there is such a command. pm install /sdcard/app1.apk will do the same thing as adb install and can be executed in adb shell, terminal emulator, and most likely over SSH. Take a look at the output of pm for more options. There is even a switch to force the app to install directly to external storage (Gingerbread style). – Chahk Sep 1 '11 at 13:51

I am using the same method and yes SSH is great! But it seems when you SSH to Android it gets a different shell than sh so if you put sh in front of the command it should work.

Here's an example: sh /system/bin/pm install app1.apk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.