Help, adb is not found!
So you’ve downloaded Android Studio and installed the SDK. Eventually you may come across a tutorial telling you to type adb
, maybe to enable debug mode in Firebase. That’s when it happens:
command not found: adb
or:
adb : The term 'adb' is not recognized as the name of a cmdlet, function, script file, or operable program.
If your first instinct is to search for “how to install adb,” you’ll likely end up with some instructions about installing it in via your operating system’s package manager or downloading random zip files from phone customization websites. But this isn’t necessary! adb
ships with the Android SDK installed by Android Studio, and with a couple of manual steps you can ensure that you’re always using the same up to date tools that your IDE is!
What’s the deal with adb?
adb
stands for the “Android Debug Bridge,” which is a command line utility that is the debug multitool for Android. Typically it’s installed via Android Studio when you install the Android SDK under platform-tools
, but it takes some amount of setup for your operating system to know to look there.
First open up Android Studio and navigate to “Tools > SDK Manager” from the menu.
Towards the top of the window, you can see the path where the IDE installed the Android SDK.
Now open up your terminal, type cd
and paste in this path. This will work on Windows, MacOS, and Linux, but on Windows you may need to press shift+insert
to paste into a terminal:
Next type cd platform-tools
:
Then type ls
(or dir
on Windows). You should see adb
or adb.exe
depending on your operating system. From here you can type ./adb
and see some program output.
You can run adb
now, but I’ve never found a tutorial that starts with “copy your SDK path, cd into platform-tools, and type ./
before adb
.” To get the experience many Android devs enjoy, you must update your PATH
environment variable. This will be different on each operating system, and I’ll list out MacOS and Windows below. On Linux the steps can vary, but the MacOS instructions will work in some cases.
MacOS Configuration
MacOS (and Linux) users will typically use zsh
or bash
for their shell. To temporarily add the platform-tools
directory to your PATH
, type:
PATH="<path from the SDK manager>/platform-tools:$PATH"
So in my example above, this becomes:
PATH="/Users/martinpatrick/Library/Android/sdk/platform-tools:$PATH"
Now, whenever you type adb
in this terminal window you can execute adb
commands. But how do you get this to stick?
Since Android Studio tends to install the Android SDK in your user directory, you’ll want to edit the PATH
for your user. And since it’s a command line utility, you’ll only need to update it for your terminal (as opposed to Mac GUI applications). To do this, you’ll want to edit the .profile
file in your home directory (if this doesn’t exist, .bash_rc
will achieve a similar result). This file will be hidden by default, so you may not see it Finder. Open this file in your favorite text editor:
nano ~/.profile
and add this to the bottom:
export ANDROID_SDK_ROOT="<your Android SDK path>"export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
Which, on my machine becomes:
export ANDROID_SDK_ROOT="/Users/martinpatrick/Library/Android/sdk"export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
Adding the extra define for ANDROID_SDK_ROOT
is unnecessary, but it may help with some more complicated power user tools as well, such as the Cocos 2D command line utility.
With that, open a new terminal window and type adb
. If you’ve done everything right, you’ll get a help page listing adb
's usage.
Windows Configuration
Windows is slightly different, and I’ll work entirely in Power Shell. Just like before, I can use the SDK manager to find my install location:
And I can change directory to find my platform tools:
Now to update the path in PowerShell, you’d type:
$env:PATH += ";<your Android SDK directory>\platform-tools"
so in my case:
$env:PATH += ";C:\Users\pux19\AppData\Local\Android\Sdk\platform-tools"
To persist this PATH
variable across multiple terminal windows (and in the normal cmd.exe
prompt if you prefer), we can set this variable for the user in a GUI utility.
The easiest way to change this setting is to click on the Windows menu and search for “Edit the system environment variables” (I usually search for “environment variables”):
Then click on “Environment Variables”
Double click “Path” in the “User variables” section
Then click on a new cell and paste in the path to your platform-tools
directory:
In my case this is C:\Users\pux19\AppData\Local\Android\Sdk\platform-tools
Once you click “OK” on all the windows you’ve opened up, new terminal windows will respond to adb
when you type it. Microsoft typically recommends logging out and in again to persist this information, but that won’t be strictly necessary unless you need to use this in a GUI application.
Wrap Up
With that, you can freely manage and debug your phone, tablet, or even set top box right from your command line. Also note that some tools will often ship with their own SDK installations. The same steps, with some minor modifications, can make any Android SDK your “default.” Just remember to only have one in your PATH
at a time, and you’ll have to manually update this path if you decide to uninstall the dev tools — even Android Studio.