8

How to install app from command line (terminal)?

I would like to start a terminal window and do the apk installation from command line (shell script)

EDIT1: within the phone. Also is it possible to install from Google Play from URL, instead just a local path?

I didn't get answer, how to install Google Play app from command line.

9

Given enough privileges (ADB, root, system application) you can use simple terminal commands to install apps:

On a PC:

Run the simple command

adb install <path to .apk file>

and the app will be installed.
This requires adb to be installed and debugging mode enabled.
The file has to be located on the PC.

In adb shell or a terminal on the device:

pm install <path to .apk file>

This is basically the same as the PC method but requires the file to be placed on the phone.
Additionally privileges to install apps are required (ADB shell inherits them from the system, other terminal apps require root)

  • 2
    Sometimes, installing from the device with pm install <package.apk> fails with Failure [INSTALL_FAILED_INVALID_URI]. If on CM12.1 or otherwise having root permissions and the adb client on the phone, it's possible to work around this by making the phone connect to itself. To do so, you need to execute setprop service.adb.tcp.port 5555, then adb start-server, then adb connect 127.0.0.1:5555, then finally adb shell "pm install <apk_path>". All of the commands are to be executed as root. – Death Mask Salesman Feb 18 '17 at 14:11
  • 2
    Lastly, if you use my abovementioned method, there are times when adb will report a dummy emulator-5554 under adb devices. Killing it via adb emu kill doesn't work, but issuing setprop service.adb.tcp.port 5555 once more will make the dummy emulator disappear. The setprop command has to be executed when the adb server is running, or else the dummy emulator won't disappear. – Death Mask Salesman Feb 18 '17 at 14:24
  • Hi @DeathMaskSalesman, I am on CM13 and i'm getting the INVALID_URI error. Since I'm able to install the apk with adb and my laptop I'd really be interested in getting your solution to work, so I can do it without the need for a pc. Just one question... how do you install adb in the phone? find / -name 'adb' only gave me three folders... Looking online I couldn't find anything – Giacomo Tecya Pigani Feb 22 '17 at 18:41
  • @GiacomoTecyaPigani You could try your luck with a version of ADB I extracted from my CM12.1 system. After downloading it from here, remount /system in read-write mode, copy the binary to /system/bin, issue chown root.shell /system/bin/adb, chmod 755 /system/bin/adb and chcon u:object_r:system_file:s0 /system/bin/adb and see if it works. – Death Mask Salesman Feb 22 '17 at 19:09
  • 1
    Thanks @DeathMaskSalesman, but sadly it didn't work. I solved it downgrading to a previous CM13 release (since the one I was using was already the latest for my device) – Giacomo Tecya Pigani Feb 24 '17 at 17:37

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.