125

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?

Alex P.
  • 30,437
  • 17
  • 118
  • 169
skoko
  • 1,431
  • 2
  • 12
  • 13
  • 5
    note: putting spaces before and/or after the equals sign causes problems. it should look like "export PATH=${PATH}:/Users/simon/Libs/android-sdk-mac_x86/tools" – Ben H Mar 15 '12 at 17:25

17 Answers17

304

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

Tobrun
  • 18,291
  • 10
  • 66
  • 81
  • 2
    The penultimate step in the above step is "Restart Terminal" :) – Brijesh Thakur Feb 20 '14 at 05:09
  • 14
    Restart terminal should not be necessary, reloading the file should be enough – Tobrun Feb 20 '14 at 09:27
  • 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. – Tobrun Oct 05 '14 at 13:02
  • 2
    can use export PATH=$PATH:$HOME/Library/Android/sdk/platform-tools/ , just by copy and paste and no need to change the _username_ – Mohit Sep 14 '15 at 06:28
  • 1
    I removed the `sdk/platform-tools/` bit at the end, since this was giving me a bash warning in Android Studio. – Ryan R Dec 18 '15 at 23:10
  • 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! – sud007 Mar 29 '16 at 06:19
  • You can also do `source ~/.bash_profile` instead of restarting the terminal. – Justin Noel Feb 07 '19 at 18:20
  • 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. – Rahul Rastogi Feb 11 '20 at 12:45
66

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

brismuth
  • 36,149
  • 3
  • 34
  • 37
43

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.

LaC
  • 12,624
  • 5
  • 39
  • 38
  • Tried both ./adb and adb.. Nothing, I have no idea what is wrong with this. – skoko Apr 02 '11 at 23:08
  • 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). – LaC Apr 02 '11 at 23:10
  • 1
    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 – skoko Apr 02 '11 at 23:13
  • @LaC, missing execute permissions on the file would be reported with `bash: /bin/ls: Permission denied` – sarnold Apr 02 '11 at 23:24
  • 1
    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. – skoko Apr 02 '11 at 23:24
  • @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? – sarnold Apr 02 '11 at 23:26
  • 1
    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 – skoko Apr 07 '11 at 09:11
27

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
David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
13

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
scottyab
  • 23,621
  • 16
  • 94
  • 105
  • 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). – Adam Jan 17 '15 at 23:07
13

The answer for MAC should be:

  1. Open your bash_profile with the following commands: open ~/.bash_profile

  2. In case base profile file doesn't exist, create a new one with the following command: touch .bash_profile then repeat phase 1.

  3. Add the following line: export PATH=/Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH

  4. Restart your bash window and test by typing adb shell

Good luck! :-)

Avi Levin
  • 1,868
  • 23
  • 32
10

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 is very important check if adb was set into path

adb version

It should be fine now.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
kotini tirumula
  • 101
  • 1
  • 2
8

I use zsh and Android Studio. I use a variable for my Android SDK path and configure in the file ~/.zshrc:

export ANDROID_HOME=/Applications/Android\ Studio.app/sdk
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"

Note: Make sure not to include single or double quotes around the specified path. If you do, it won't work.

colabug
  • 2,602
  • 2
  • 22
  • 28
7

Android Studio v1.2 installs the adb tool in this path:

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

So it goes like this:

  1. Run Terminal
  2. run adb version and expect an error output
  3. touch ~/.bash_profile
  4. open ~/.bash_profile
  5. add the above path before the 'closing' :$PATH
  6. source ~/.bash_profile
  7. run adb version and expect an output

Good luck!

nurnachman
  • 4,468
  • 2
  • 37
  • 40
3

In order to make the terminal always have the file ~/.bashrc and there put the path you wish to use, by adding:

export PATH=$PATH:/XXX

where XXX is the path that you wish to use.

for adb, here's what i use:

export PATH=$PATH:/home/user/Android/android-sdk-linux_x86/platform-tools/

(where "user" is my user name).

Chris
  • 7,270
  • 19
  • 66
  • 110
android developer
  • 114,585
  • 152
  • 739
  • 1,270
3

It appears that you're still trying to execute adb with ./adb. That asks the shell to run the program named adb in the current working directory.

Try just adb without ./.

sarnold
  • 102,305
  • 22
  • 181
  • 238
  • Tried that too. Nothing. This is seriously driving me nuts. – skoko Apr 02 '11 at 23:07
  • @user569594: did you re-start your shell after editing `.profile`? (i.e., if you `echo $PATH` before `adb`, do you see the new directories?) – sarnold Apr 02 '11 at 23:18
  • yes, I mentioned that in the question. It shows up in the echo, bash for some reason just CAN NOT SEE IT. – skoko Apr 02 '11 at 23:21
  • @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... :) – sarnold Apr 02 '11 at 23:22
  • Yea, I made sure to restart. The problem lied in having two profiles in my home directory. A .bash_profile and a .profile – skoko Apr 07 '11 at 09:10
  • @user569594, cool! If that's the case, @David Caunt's answer looks like the one to `Accept`. :) – sarnold Apr 07 '11 at 09:11
2

enter image description here

2nd solution is explained below. But when i close the terminal the change which i made in path variable gets lost. Thus i prefer the first way!

enter image description here

metis
  • 1,024
  • 2
  • 10
  • 26
2

If you are Catalina user follow this

  1. Make sure to be in the Home directory

    cd ~

  2. To persist PATH changes and prevent it to be cleaned up after closing the Terminal app, you need to keep the variables in the zshrc file for Catalina

    touch .zshrc

  3. Open it with the TextEditor

    open -e .zshrc

  4. Insert the command below to add ADB as PATH variable (replace username with your own)

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

  5. Save the file and close the TextEditor app. Back to the Terminal app, insert the following to source the file

    source .zshrc

  6. And you’re done! Let’s test if it was successful

    adb version

  7. You should expect something like

    Android Debug Bridge version 1.0.41 Version 31.0.2-7242960 Installed as /Users/username/Library/Android/sdk/platform-tools//adb

Aristo Michael
  • 2,166
  • 3
  • 35
  • 43
1

I added export PATH=${PATH}:/Users/mishrapranjal/android-sdks/platform-tools/ into both places .bash_profile and .profile to make sure it works. Still it wasn't working and then I looked at sarnold's tip about restarting terminal and it worked like a charm. It saved my time of adding every time this into the PATH whenever I had to run adb. Thank you guys.

Community
  • 1
  • 1
Pranjal
  • 179
  • 1
  • 7
  • Instead of relauching your terminal you can use the following command to reload the file: "*. .bash_profile*" – Tobrun Nov 04 '13 at 08:53
0

If anyone can't seem to get there .bash_profile file to take any new Paths AND you have other commands in that file (like alias commands) then try moving the PATH statements to the top of the file.

That is the only thing that worked for me. The reason it worked was because I had some typos in my alias commands and apparently this file throws an error and exits if it runs into a problem. So that is why my PATH statements weren't being run. Moving it to the top just let it run first.

JoshJoe
  • 1,482
  • 2
  • 17
  • 35
0

In bash profile just add -

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

and then in terminal run -

adb version

0

All answers are well written and helpful but there is one thing that I want to mention. Before adding path variable to .bash_profile kindly check your default shell.

Because i was seting path variable in .bash_profile file but my default shell was zsh that's why i have to run source ~/.bash_profile each time before using adb command.

So first check your default shell:

echo $SHELL
  • if the output is /bin/bash then you should set path variable in .bash_profile
  • If the output is /bin/zsh then you should set path variable in .zshrc

And here is my path variable:

export ANDROID_SDK_ROOT="/Users/aliasjad/Library/Android/sdk"
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
Ali Asjad
  • 1,489
  • 1
  • 10
  • 11