Trying to add adb to PATH variable OSX

157,190

Solution 1

Why are you trying to run "./adb"? That skips the path variable entirely and only looks for "adb" in the current directory. Try running "adb" instead.

Edit: your path looks wrong. You say you get

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Libs/android-sdk-mac_x86/tools:/Libs/android-sdk-mac_x86/platform-tools

You're missing the /Users/simon part.

Also note that if you have both .profile and .bash_profile files, only the latter gets executed.

Solution 2

Add to PATH for every login

Total control version:

in your terminal, navigate to home directory

cd

create file .bash_profile

touch .bash_profile

open file with TextEdit

open -e .bash_profile

insert line into TextEdit

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

save file and reload file

source ~/.bash_profile

check if adb was set into path

adb version


One liner version

Echo your export command and redirect the output to be appended to .bash_profile file and restart terminal. (have not verified this but should work)

echo "export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/ sdk/platform-tools/" >> ~/.bash_profile

Solution 3

Alternative: Install adb the easy way

If you don't want to have to worry about your path or updating adb manually, you can use homebrew instead.

brew cask install android-platform-tools

Solution 4

On my Macbook Pro, I've added the export lines to ~/.bash_profile, not .profile.

e.g.

export PATH=/Users/me/android-sdk-mac_86/platform-tools:/Users/me/android-sdk-mac_86/tools:$PATH

Solution 5

Just encase anyone finds this SO post when using Android Studio which includes the SDK has part of the App package (on Mac OSX).

So as @davecaunt and @user1281750 noted but insert the following line to .bash_profile

export PATH=/Applications/Android\ Studio.app/sdk/tools:/Applications/Android\ Studio.app/sdk/platform-tools:$PATH
Share:
157,190
skoko
Author by

skoko

Updated on September 03, 2021

Comments

  • skoko
    skoko over 2 years

    I am trying to develop for android and I want to add the adb to my PATH so that I can launch it really easily. I have added directories before by for some reason adb does not want to be found. This is very frustrating. Has anyone else had this problem before?

    I created a file .profile and added the following to it.

    export PATH = ${PATH}:/Users/simon/Libs/android-sdk-mac_x86/platform-tools/
    export PATH = ${PATH}:/Users/simon/Libs/android-sdk-mac_x86/tools
    

    When I check my environment path I see the following:

    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Libs/android-sdk-mac_x86/tools:/Libs/android-sdk-mac_x86/platform-tools
    

    So I know that it is added to my PATH variable. Now when I try to run adb I get that it is not found.

    -bash: ./adb: No such file or directory
    

    This is very very frustrating. Could it be a problem with permissions? Has anyone had this problem with OSX and Android?

  • skoko
    skoko about 13 years
    Tried that too. Nothing. This is seriously driving me nuts.
  • skoko
    skoko about 13 years
    Tried both ./adb and adb.. Nothing, I have no idea what is wrong with this.
  • skoko
    skoko about 13 years
    funny. I opened up that file...This exact line was already in there. I think eclipse added that while installing the plug-in?
  • LaC
    LaC about 13 years
    Where is adb supposed to be located? Check that it's there and that it has execute permissions (cd to the directory and do ls -l adb).
  • skoko
    skoko about 13 years
    If I go to the directory I can run it no problem. Here is the output. -rwxrwxrwx 1 simon staff 179312 28 Feb 02:48 adb
  • sarnold
    sarnold about 13 years
    @user569594: did you re-start your shell after editing .profile? (i.e., if you echo $PATH before adb, do you see the new directories?)
  • skoko
    skoko about 13 years
    yes, I mentioned that in the question. It shows up in the echo, bash for some reason just CAN NOT SEE IT.
  • sarnold
    sarnold about 13 years
    @user569594: sorry, had to ask, I've seen people edit their shell start-up scriptss, test their changes by starting a new shell, and forget to re-start their current shell and wonder where it fails... :)
  • David Snabel-Caunt
    David Snabel-Caunt about 13 years
    It is possible, though I added mine myself.
  • sarnold
    sarnold about 13 years
    @LaC, missing execute permissions on the file would be reported with bash: /bin/ls: Permission denied
  • skoko
    skoko about 13 years
    Thanks for this answer. It turns out both .profile and .bash_profile were both there. I had the values in .profile and yea. Now it works. Thanks a lot guys.
  • David Snabel-Caunt
    David Snabel-Caunt about 13 years
    According to johnnywey.wordpress.com/2008/04/17/fixing-bash-profile-in-os‌​-x you may have conflicting profiles
  • sarnold
    sarnold about 13 years
    @user569594: I don't like that your adb executable is world-writable. I wonder if Apple has modified bash to not execute world-writable executables? Try chmod 755 adb and try again?
  • skoko
    skoko about 13 years
    I think that's exactly what the problem was. Another app (I think MacPorts) created .profile
  • skoko
    skoko about 13 years
    Yea, I made sure to restart. The problem lied in having two profiles in my home directory. A .bash_profile and a .profile
  • skoko
    skoko about 13 years
    Works now, I just had two profiles. One over wrote the other. If anyone is doing this use .bash_profile to edit the path variable. I followed a different tutorial that said to use .profile
  • sarnold
    sarnold about 13 years
    @user569594, cool! If that's the case, @David Caunt's answer looks like the one to Accept. :)
  • Tobrun
    Tobrun over 10 years
    Instead of relauching your terminal you can use the following command to reload the file: ". .bash_profile"
  • Brijesh Thakur
    Brijesh Thakur about 10 years
    The penultimate step in the above step is "Restart Terminal" :)
  • Tobrun
    Tobrun about 10 years
    Restart terminal should not be necessary, reloading the file should be enough
  • Adam Johns
    Adam Johns almost 10 years
    Don't forget to restart terminal after you add to PATH.
  • rilar
    rilar over 9 years
    Awesome! Thx scottyab!
  • Tobrun
    Tobrun over 9 years
    Update: Probably it doesn't work for you because you are using multiple tabs. Every tab on your terminal has his own session. So reload the .bash_profile in the tab of the "adb version" command.
  • Adam
    Adam over 9 years
    Alternatively, it's located in Users/[user]/Android/sdk/platform-tools.... I don't like linking to the Applications folder (maybe that's just me though).
  • Mohit
    Mohit over 8 years
    can use export PATH=$PATH:$HOME/Library/Android/sdk/platform-tools/ , just by copy and paste and no need to change the username
  • smets.kevin
    smets.kevin over 8 years
    Much, MUCH better then trying to fiddle with PATH, .bash_profile etc.. Thanks!
  • Ryan R
    Ryan R over 8 years
    I removed the sdk/platform-tools/ bit at the end, since this was giving me a bash warning in Android Studio.
  • sud007
    sud007 about 8 years
    I checked like 7 different versions of this tutorial. And I was only able to understand this one and what I am trying to do here! Great, It worked!
  • Adam Mendoza
    Adam Mendoza over 7 years
    yup c[_] ~ ᒡ◯ᵔ◯ᒢ
  • The Hungry Androider
    The Hungry Androider about 7 years
    FYI, this now gives the error: Error: No available formula with the name "android-platform-tools". Use: brew install Caskroom/cask/android-platform-tools instead
  • brismuth
    brismuth about 7 years
    @The Hungry Androider - fixed it
  • Kinergy
    Kinergy about 6 years
    I haven't tried this but I'm wondering if one installs Android Studio as well as with Homebrew, wondering if this could create a version out of sync problem in the future... just a thought
  • brismuth
    brismuth about 6 years
    If you have multiple installations, bash will just use one of them consistently (as long as your path is configured the same each time).
  • Justin Noel
    Justin Noel over 5 years
    You can also do source ~/.bash_profile instead of restarting the terminal.
  • xtarsy
    xtarsy almost 5 years
    Best and easiest answer!
  • Rahul Rastogi
    Rahul Rastogi over 4 years
    My adb command works after using first method, but working till the terminal is opened in the same session. As I close terminal and open new window, then again adb commands doesn't respond.
  • Seyid-Kanan Bagirov
    Seyid-Kanan Bagirov almost 4 years
    First method work for me, then you need restart your computer
  • Rahul Mishra
    Rahul Mishra over 3 years
    This works now: brew install --cask android-platform-tools