Skip to content

Instantly share code, notes, and snippets.

@isti03
Last active April 26, 2024 21:27
Show Gist options
  • Save isti03/4104cc33dbf5b741add2a27c8d3a41df to your computer and use it in GitHub Desktop.
Save isti03/4104cc33dbf5b741add2a27c8d3a41df to your computer and use it in GitHub Desktop.
Install ADB (Android Debug Bridge) on Linux and useful snippets

Getting ADB (Android Debug Bridge) working on linux can be a bit harder than on other operating systems. This guide aims to help with that.

Installation

1. Install the adb package

Just use your package manager

2. Add yourself to the plugdev group

sudo groupadd plugdev
sudo usermod -a -G plugdev $USER

Then reboot

3. Enable Usb debugging on your device

See https://www.getdroidtips.com/enable-usb-debugging/

4. Connect to your device

  • Unlock your device
  • Run the command adb devices
  • Authorize access on a pop-up on your device
  • Re-run adb devices. You should see your device id, and device next to it.
  • If you get an error, no permissions (user in plugdev group; are your udev rules wrong?), install the android-udev package and reboot.

Snippets

Enter device shell

Use adb shell to enter device shell, where you can issue basic Unix and Linux commands. You can use the pm package manager as well. Use the exit command to quit out of the shell.

Filter packages

adb shell pm list packages <searched-name>

Remove user installed packages

adb shell pm uninstall <package-name>

Remove system packages for current user

Warning: This can cause a bootloop if you uninstall an important system package. Check on the internet, whether the removal of the package is safe.

If you encounter a bootloop, you have to reset your device in the recovery menu.

adb shell pm uninstall -k --user 0 <package-name>

Reinstall uninstalled system packages

If you can still boot your phone up, but you want to reinstall a package, use: adb shell cmd package install-existing <package-name>

Copy files or directories

adb pull remote local adb push local remote

Install apk from the computer

adb install program.apk

Port forward and reverse

If the server is on the phone: adb forward tcp:3000 tcp:3000

If the server is on the computer: adb reverse tcp:3000 tcp:3000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment