349

I have installed Android SDK and Eclipse on my Mac system. I am able to program using Eclipse and have created few sample applications. But I am still not able to access adb through the terminal window. I have tried following command in terminal:

$ pwd
/Users/espireinfolabs/Desktop/soft/android-sdk-mac_x86/platform-tools

$ ls
NOTICE.txt  dexdump     llvm-rs-cc-2
aapt        dx          llvm-rs-cc.txt
adb         lib         source.properties
aidl        llvm-rs-cc

$ adb --help
-bash: adb: command not found

I have also added the ls output so that you know in which window I am.

slhck
  • 36,575
  • 28
  • 148
  • 201
pankaj
  • 7,878
  • 16
  • 69
  • 115

21 Answers21

676

The problem is: adb is not in your PATH. This is where the shell looks for executables. You can check your current PATH with echo $PATH.

Bash will first try to look for a binary called adb in your Path, and not in the current directory. Therefore, if you are currently in the platform-tools directory, just call

./adb --help

The dot is your current directory, and this tells Bash to use adb from there.

But actually, you should add platform-tools to your PATH, as well as some other tools that the Android SDK comes with. This is how you do it:

  1. Find out where you installed the Android SDK. This might be (where $HOME is your user's home directory) one of the following (or verify via Configure > SDK Manager in the Android Studio startup screen):

    • Linux: $HOME/Android/Sdk
    • macOS: $HOME/Library/Android/sdk
  2. Find out which shell profile to edit, depending on which file is used:

    • Linux: typically $HOME/.bashrc
    • macOS: typically $HOME/.bash_profile
    • With Zsh: $HOME/.zshrc
  3. Open the shell profile from step two, and at the bottom of the file, add the following lines. Make sure to replace the path with the one where you installed platform-tools if it differs:

    export ANDROID_HOME="$HOME/Android/Sdk"
    export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
    
  4. Save the profile file, then, re-start the terminal or run source ~/.bashrc (or whatever you just modified).

Note that setting ANDROID_HOME is required for some third party frameworks, so it does not hurt to add it.

slhck
  • 36,575
  • 28
  • 148
  • 201
  • 11
    type "source .bash_profile" or open a new terminal tab after adding that line to start using it inmediately – Maragues Jan 09 '13 at 14:56
  • 4
    To edit the `~/.profile` file in TextEdit, simply enter `open ~/.profile` in Terminal. – Michael Innes Jul 09 '13 at 21:33
  • I have heard that "if you have both .profile and .bash_profile files, only the latter gets executed." I would imagine that the path needs to be inserted into `~/.bash_profile` instead of just `~/.profile`. – Michael Innes Jul 09 '13 at 21:53
  • 1
    Lastly, what worked for me was NOT having the `/:$PATH` at the end of the line. – Michael Innes Jul 09 '13 at 21:55
  • @Eptin If you don't add your existing path while exporting a new one, you're not going to be able to use any binaries except for shell builtins or the Android platform tools. – slhck Jul 10 '13 at 07:23
  • Just wanted to report that with AndroidStudio the sdk is now included in the Application package. So how would I write out that path? – marciokoko Jan 31 '14 at 14:12
  • @marciokoko I haven't used it, but you can search through the application's files for the `adb` executable. – slhck Jan 31 '14 at 14:22
  • I found it, but the problem is that its inside Applications/Android Studio.app/ where there is an sdk folder inside platform-tools. But if I write export PATH=/Applications/Android Studio.app/sdk/platform-tools:$PATH I get this: -bash: export: `Studio.app/sdk/platform-tools:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin': not a valid identifier – marciokoko Jan 31 '14 at 14:28
  • 1
    @marciokoko You need to put the path into quotes, e.g. `export PATH="/Applications/Android Studio.app/sdk/platform-tools":$PATH`. Otherwise the space will be treated as a separator. – slhck Jan 31 '14 at 14:31
  • I had to write it like this because of the space = export PATH=“/Applications/Android\ Studio.app/sdk/platform-tools”:$PATH but adb devices still returns command not found – marciokoko Jan 31 '14 at 14:36
  • @marciokoko Make sure to restart your shell. Or come to chat and we'll troubleshoot this: http://chat.stackexchange.com/rooms/118/root-access – slhck Jan 31 '14 at 14:40
  • Wow Android Studio has been around since 2011? – Arthur Collé Sep 12 '14 at 21:31
  • Just Export the path, it 's the simplest way that works. export PATH=path-to-folder/android-sdk-mac_x86/platform-tools:$PATH my thx goes to @slhck – TheFuquan Nov 13 '14 at 08:10
  • 15
    In more recent Android Studio releases: "/Users//Library/Android/sdk/platform-tools" so it will be the following: export PATH="/Users/myuser/Library/Android/sdk/platform-tools":$PATH – eb80 Jan 10 '15 at 15:43
  • Worked for me, but I need do this every time after restart Android Studio – hov.terteryan Jun 20 '17 at 13:22
  • @hovo888s Not sure how restarting Android Studio has an effect on this – the PATH should be added to your shell profile (`.bashrc` or `.bash_profile` on OS X, or `.zshrc` for Zsh, etc.). It will then always be available. What doesn't work when you restart Android Studio? Any specific error? – slhck Jun 20 '17 at 16:11
  • @hovo888s That doesn't make much sense… if you add the `PATH` to your shell profile it does not automatically disappear. Please ask a new question about this, describe exactly what you are doing, and we'll figure out what the problem is. – slhck Jun 20 '17 at 18:53
216

For zsh users. Add alias adb='/Users/$USER/Library/Android/sdk/platform-tools/adb' to .zshrc file.

Then run source ~/.zshrc command

Tristan Richard
  • 3,385
  • 1
  • 15
  • 17
133
  1. run command in terminal nano $HOME/.zshrc

  2. Must include next lines:

    export PATH=$PATH:~/Library/Android/sdk/platform-tools
    export ANDROID_HOME=~/Library/Android/sdk
    export PATH="$HOME/.bin:$PATH"
    export PATH="~/Library/Android/sdk/platform-tools":$PATH
    
  3. Press Ctrl + X to save file in editor,Enter Yes or No and hit Enter key

  4. Run source ~/.zshrc

  5. Check adb in terminal, run adb

Prakash
  • 7,794
  • 4
  • 48
  • 44
Andrey Patseiko
  • 3,687
  • 1
  • 25
  • 24
76

In addition to slhck, this is what worked for me (mac).

To check where your sdk is located.

  1. Open Android studio and go to:

File -> Project Structure -> Sdk location

  1. Copy the path.

  2. Create the hidden .bash_profile in your home.

  3. (open it with vim, or open -e) with the following:

export PATH=/Users/<Your session name>/Library/Android/sdk/platform-tools:/Users/<Your session name>/Library/Android/sdk/tools:$PATH

  1. Then simply use this in your terminal: . ~/.bash_profile

SO post on how to find adb devices

kemicofa ghost
  • 16,349
  • 8
  • 82
  • 131
68

Quick Answer

Pasting this command in terminal solves the issue in most cases:

** For Current Terminal Session:

  • (in macOS) export PATH="~/Library/Android/sdk/platform-tools":$PATH
  • (in Windows) i will update asap

** Permanently:

  • (in macOS) edit the ~/.bash_profile using vi ~/.bash_profile and add this line to it: export PATH="~/Library/Android/sdk/platform-tools":$PATH

However, if not, continue reading.


Detailed Answer

Android Debug Bridge, or adb for short, is usually located in Platform Tools and comes with Android SDK, You simply need to add its location to system path. So system knows about it, and can use it if necessary.

Find ADB's Location

Path to this folder varies by installation scenario, but common ones are:


  • If you have installed Android Studio, path to ADB would be: (Most Common)
    • (in macOS) ~/Library/Android/sdk/platform-tools
    • (in Windows) i will update asap

  • If you have installed Android Studio somewhere else, determine its location by going to:

    • (in macOS) Android Studio > Preferences > Appearance And Behavior > System Settings > Android SDK and pay attention to the box that says: Android SDK Location
    • (in Windows) i will update asap

  • However Android SDK could be Installed without Android studio, in this case your path might be different, and depends on your installation.

Add it to System Path

When you have determined ADB's location, add it to system, follow this syntax and type it in terminal:

  • (in macOS)

    export PATH="your/path/to/adb/here":$PATH

    for example: export PATH="~/Library/Android/sdk/platform-tools":$PATH

Hamid Asghari
  • 5,751
  • 4
  • 24
  • 34
51

I don't know how did you install the android SDK. But in Mac OS, what really worked for me is to reinstall it using brew. All problems solved in a row.

brew install --cask android-sdk

Later on:

android update sdk --no-ui --filter 'platform-tools'

Like a charm

eMarine
  • 1,158
  • 1
  • 14
  • 26
  • 2
    For all mac users this is absolutely top answer for the problem, like it is in this thread -> http://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x – Stoycho Andreev Mar 15 '17 at 13:44
  • 26
    Use `brew cask install android-platform-tools` works as well – Gavin May 23 '17 at 07:11
  • 3
    It's been updated to `brew cask install android-sdk` _source_: https://github.com/NativeScript/nativescript-cli/issues/2706 –  Mar 25 '18 at 19:05
  • 6
    It's been updated to `brew install --cask android-platform-tools` – Lehlohonolo_Isaac Feb 15 '21 at 12:53
  • @Lehlohonolo_Isaac is this command replacing both commands? – eMarine Feb 16 '21 at 13:56
  • @eMarine No, it's only for replacing the first command. For the second one, you can use `brew install --cask android-sdk`. Look up https://formulae.brew.sh/cask/android-sdk#default for more – Lehlohonolo_Isaac Feb 17 '21 at 10:27
48

enter image description hereThis is how it worked for me

first I find my platform-tools than I was using zshrc instead of bash_profile so I run this command first

echo 'export PATH=${PATH}:$HOME/Library/Android/sdk/platform-tools/' >> ~/.zshrc

next refresh terminal

source ~/.zshrc

Check if it worked

adb devices

result of this command must be something similar to this if so then it worked.

List of devices attached
emulator-5554   device
Lukas1
  • 582
  • 1
  • 5
  • 28
Zeeshan Mehdi
  • 1,241
  • 1
  • 17
  • 18
40

If you have installed Android Studio on MAC here is how:

nano ~/.zshrc

or

open ~/.zshrc in VScode

Then edit the file

# Android ADB
export ANDROID_HOME="$HOME/Library/Android/sdk"
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

control + X OR Save file. Restart Terminal and try

> adb
Thiago
  • 12,778
  • 14
  • 93
  • 110
36

For me, I ran into this issue after switching over from bash to zsh so I could get my console to look all awesome fantastic-ish with Hyper and the snazzy theme. I was trying to run my react-native application using react-native run-android and running into the op's issue. Adding the following into my ~.zshrc file solved the issue for me:

export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
ragamufin
  • 4,113
  • 30
  • 32
27

UPDATE

As @Loren.A mentioned in comment latest version of brew does not support cast. So one can simply use:

brew install android-platform-tools


  1. Simply install adb with brew

    brew cask install android-platform-tools

  2. Check if adb is installed

    adb devices

Freddy
  • 2,216
  • 3
  • 31
  • 34
  • 1
    This appears to be the easiest solution. The current version of `brew` doesn't use `cask` so the command that worked for me is `brew install android-platform-tools` – Loren.A Jul 11 '22 at 15:24
  • now you only need to install homebrew, and probably upgrade python – htafoya Jan 03 '23 at 03:30
21

If you are using the Mac with the M1 chip add the below export command to the zshrc file using the nano command, if that file is not present the nano command will create it for you so run

nano ~/.zshrc

paste this path in that file without any modification

export PATH="/Users/$USER/Library/Android/sdk/platform-tools":$PATH

hit ctrl-x and then Hit y to save the changes and the hit return Key to close it without renaming the file.

then run

source ~/.zshrc

to refresh the .zshrc file

and then try runnning

adb

it should give you the desired output

Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
13

If you are using zsh on an OS X, you have to edit the zshrc file.

Use vim or your favorite text editor to open zshrc file:

vim ~/.zshrc

Paste the path to adb in this file:

export PATH="/Users/{$USER}/Library/Android/sdk/platform-tools":$PATH
div
  • 1,475
  • 3
  • 22
  • 32
6

For Mac OS Catalina or Mojave

Enter command to open nano editor

nano $HOME/.zshrc

Set PATH variable, means append more path as shown here

FLUTTER_HOME="/Users/pankaj/Library/Android/flutter-sdk/flutter/bin"
DART_HOME="/Users/pankaj/Library/Android/flutter-sdk/flutter/bin/cache/dart-sdk/bin"
ANDROID_SDK_HOME="/Users/pankaj/Library/Android/sdk"
ANDROID_ADB_HOME="/Users/pankaj/Library/Android/sdk/platform-tools"

PATH="$PATH:$FLUTTER_HOME"
PATH="$PATH:$DART_HOME"
PATH="$PATH:$ANDROID_SDK_HOME"
PATH="$PATH:$ANDROID_ADB_HOME"

Now press Command + X to save file in editor,Enter Yes or No and hit Enter key.

Pankaj Kant Patel
  • 2,050
  • 21
  • 27
  • This is a great answer – Dario Brux Oct 25 '20 at 11:11
  • great answer. would be great to add little more context behind why ".zshrc" or ".zprofile" works. https://stackoverflow.com/questions/56784894/macos-catalina-10-15beta-why-is-bash-profile-not-sourced-by-my-shell – David Kim Jul 19 '21 at 21:25
6

This worked for me on my MAC - 2020

Go to directory containing adb:

cd ~/Library/Android/sdk/platform-tools/

Run adb command to list all services

./adb shell dumpsys activity services
Rajeev Jayaswal
  • 1,423
  • 1
  • 20
  • 22
3

I couldn't get the stupid path working so I created an alias for abd

alias abd ="~/Library/Android/sdk/platform-tools/adb"

works fine.

Dazzle
  • 2,880
  • 3
  • 25
  • 52
2

For Mac, Android Studio 3.6.1, I added this to .bash_profile

export PATH="~/Library/Android/sdk/platform-tools/platform-tools":$PATH

Jordan Daniels
  • 4,896
  • 1
  • 19
  • 29
1

Or the alternative solution could be

  1. Make sure you already install for android SDK. Usually it is located under /Users/your-user-name/Library/Android/sdk
  2. If the SDK is there then run this command. ./platform-tools/adb install your-apk-location

  3. From there you can generate the APK file That's the only sample to check if adb command is there

Faris Rayhan
  • 4,500
  • 1
  • 22
  • 19
  • Thanks. It worked but I had to add sdk directory in the path for 2nd step: ./Library/Android/sdk/platform-tools/adb install ~/Downloads/apk-release.apk – Deniz Öztürk Nov 18 '18 at 10:26
1

For some reason when installed Android Studio 3.6.1 the adb file was actually in $ANDROID_HOME/platform-tools/platform-tools. not sure if this is a bug with my installation or what but this fixed it for me.

KLTR
  • 1,263
  • 2
  • 14
  • 37
0

For Mac Os the default shell has moved on to "zsh" from "bash" as of Mojave and later releases, so for all the Mac users I would suggest go with the creating ".zshrc" file. "adb" runs as it is intended to be. Thanks @slhck for your info.!

0

Follow steps below

  • Open bash_profile using open -e .bash_profile
  • write export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
  • close bash_profile file
  • run source .bash_profile
  • Done run your adb command now !!

In some cases, you may need to run source .bash_profile every time you open cmd to run adb commands

Dharman
  • 30,962
  • 25
  • 85
  • 135
-13

It's working fine..

brew install android-sdk

Later on:

android update sdk --no-ui --filter 'platform-tools'
beerwin
  • 9,813
  • 6
  • 42
  • 57