Not able to access adb in OS X through Terminal, "command not found"

347,854

Solution 1

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.

Solution 2

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

Then run source ~/.zshrc command

Solution 3

  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

Solution 4

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

Solution 5

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

Share:
347,854

Related videos on Youtube

pankaj
Author by

pankaj

Updated on April 12, 2022

Comments

  • pankaj
    pankaj about 2 years

    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.

  • Maragues
    Maragues over 11 years
    type "source .bash_profile" or open a new terminal tab after adding that line to start using it inmediately
  • Michael Innes
    Michael Innes almost 11 years
    To edit the ~/.profile file in TextEdit, simply enter open ~/.profile in Terminal.
  • Michael Innes
    Michael Innes almost 11 years
    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
    Michael Innes almost 11 years
    Lastly, what worked for me was NOT having the /:$PATH at the end of the line.
  • slhck
    slhck almost 11 years
    @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.
  • marciokoko
    marciokoko over 10 years
    Just wanted to report that with AndroidStudio the sdk is now included in the Application package. So how would I write out that path?
  • slhck
    slhck over 10 years
    @marciokoko I haven't used it, but you can search through the application's files for the adb executable.
  • marciokoko
    marciokoko over 10 years
    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
  • slhck
    slhck over 10 years
    @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.
  • marciokoko
    marciokoko over 10 years
    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
  • slhck
    slhck over 10 years
    @marciokoko Make sure to restart your shell. Or come to chat and we'll troubleshoot this: chat.stackexchange.com/rooms/118/root-access
  • Arthur Collé
    Arthur Collé over 9 years
    Wow Android Studio has been around since 2011?
  • TheFuquan
    TheFuquan over 9 years
    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
  • eb80
    eb80 over 9 years
    In more recent Android Studio releases: "/Users/<user>/Library/Android/sdk/platform-tools" so it will be the following: export PATH="/Users/myuser/Library/Android/sdk/platform-tools":$PAT‌​H
  • eMarine
    eMarine over 7 years
    Slightly similar at my answer don't you think?
  • quemeful
    quemeful over 7 years
    I couldn't figure it out because you never mentioned "Like a charm"
  • Stoycho Andreev
    Stoycho Andreev about 7 years
    For all mac users this is absolutely top answer for the problem, like it is in this thread -> stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x
  • Gavin
    Gavin almost 7 years
    Use brew cask install android-platform-tools works as well
  • hovo888s
    hovo888s almost 7 years
    Worked for me, but I need do this every time after restart Android Studio
  • slhck
    slhck almost 7 years
    @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
    slhck almost 7 years
    @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.
  • Jai Sharma
    Jai Sharma about 6 years
    It's been updated to brew cask install android-sdk source: github.com/NativeScript/nativescript-cli/issues/2706
  • Johnny Five
    Johnny Five over 5 years
    "Permanently" worked. Long story short for it: 1. vi ~/.bash_profile 2. export PATH="~/Library/Android/sdk/platform-tools":$PATH 3. :x
  • Deniz
    Deniz over 5 years
    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
  • cutiko
    cutiko over 5 years
    vi something else use the console editor for opening the file, you can also use open ~/.bash_profile
  • Yogesh Umesh Vaity
    Yogesh Umesh Vaity over 5 years
    This worked for me. Don't forget to source ~/.zshrc for the changes to take effect!
  • Guy West
    Guy West over 4 years
    nano ~/.zshrc export PATH="/Users/{$USER}/Library/Android/sdk/platform-tools":$PA‌​TH
  • Dario Brux
    Dario Brux over 3 years
    This is a great answer
  • Lehlohonolo_Isaac
    Lehlohonolo_Isaac over 3 years
    It's been updated to brew install --cask android-platform-tools
  • eMarine
    eMarine over 3 years
    @Lehlohonolo_Isaac is this command replacing both commands?
  • Lehlohonolo_Isaac
    Lehlohonolo_Isaac over 3 years
    @eMarine No, it's only for replacing the first command. For the second one, you can use brew install --cask android-sdk. Look up formulae.brew.sh/cask/android-sdk#default for more
  • Zeeshan Shabbir
    Zeeshan Shabbir about 3 years
    step 3 Press Control + X to save file in editor,Enter Yes or No and hit Enter key
  • Däñish Shärmà
    Däñish Shärmà about 3 years
    Thanks for the exact answer. Other's answers are very much confusing.
  • David Kim
    David Kim almost 3 years
    great answer. would be great to add little more context behind why ".zshrc" or ".zprofile" works. stackoverflow.com/questions/56784894/…
  • Najam Us Saqib
    Najam Us Saqib over 2 years
    clean solution. Worked first time.
  • Hardik Desai
    Hardik Desai over 2 years
    Also worked on mac os big sur
  • Anthony Cannon
    Anthony Cannon over 2 years
    I had to close and start a new terminal after for this to work
  • Sonu Sourav
    Sonu Sourav over 2 years
    For me I had to use my username i.e. sonusourav in place of {$USER} probably because USER was not defined
  • Sagar Patel
    Sagar Patel about 2 years
    Worked for me in MacOS Monterey Version 12.2.1
  • PRANAV SINGH
    PRANAV SINGH about 2 years
    Short and clean solution worked in first attempt
  • Daniel Beltrami
    Daniel Beltrami about 2 years
    You can use "$USER" instead of <yourUserName>, to make this more dynamic.
  • MusabAlothman
    MusabAlothman about 2 years
    Finalllly, thanks mate worked on Big Sur 11.6.4
  • bfrguci
    bfrguci about 2 years
    Ln 1 looks like doing the same thing with Ln 4. What is the point? What is the purpose of Ln 3 though?
  • Sulfy
    Sulfy almost 2 years
    working solution