How To: Create a .bash_profile on your Mac running OSX Snow Leopard to run Android ADB from any folder and without ./

The Android SDK is very easy to get up and running on OSX, it doesn’t require any drivers or anything, just run the android app and it does it’s thing.

Unfortunately, OSX doesn’t have a .bash_profile by default. Without creating a .bash_profile and adding your sdk/tools folder to path, you’ll need to navigate to the tools folder of your sdk and run scripts locally when using stuff like ADB and fastboot.

I know that just gave you a headache, so I’ll clarify with examples.

Let’s say you download the sdk, and unzip it to yourusername/android-sdk-mac_86

In order to run adb, you’ll need to open terminal, and type

cd android-sdk-mac_86/tools

then you’ll need to start every command with the dot slash ( ./ ), which tells the terminal to run commands from the folder you are currently in.

For example,

adb shell

attempts to run the script adb, with the command shell, to open a shell, and it looks for the scripts where ever it thinks scripts will be. On a Mac, it only looks in /bin by default. This is where the scripts for the commands you use to navigate in terminal are stored. It contains stuff like ls, mkdir, cd, etc.

If you want it to run a script from your current location in terminal, you have to add the dot slash. For example, still in your sdk/tools folder, the command

./adb shell

Will attempt to run the script “adb” with the command “shell” from your current location, in this case, sdk/tools.

We’re going to add sdk/tools to the places OSX looks for scripts, so you don’t need to be in that folder in order to use adb or any other SDK script. For instance, you can navigate to the desktop and use ADB to install an APK on your desktop without moving it to the tools folder. Clear as mud? Great.

Press Command (apple) + space and a spotlight search window will pop up in the upper right corner. Start typing “Terminal” until you see it highlighted, and press enter. A terminal window will open.

Type:

cd

Press enter. You should be in your root directory.

Now type:

touch .bash_profile

then press enter. You just created a file called “.bash_profile”. Now open it with text editor using this command:

open -e .bash_profile

Pressing enter will make text edit pop up, it’s likely blank, since you just created it. In the text file, paste this:

export PATH=${PATH}:/Users/yourname/whereveryoursdk/islocated/tools

Obviously replace yourname and the path to your sdk/tools folder with the correct info for your install.

Save the file and close text edit.

If you did it right, you’re done. With your android phone plugged in, type

adb devices

and if you get a device returned, you’re good to go.

12/07/10 Update:

It appears that updating your SDK to include all the new gingerbread stuff moves ADB from sdk/tools to /sdk/platform-tools. Basically, all you need to do is add one more line to .bash_profile. Under the line you added earlier, something like:

export PATH=${PATH}:/Users/yourname/whereveryoursdk/islocated/tools

Add this:

export PATH=${PATH}:/Users/yourname/whereveryoursdk/islocated/platform_tools


2 comments to How To: Create a .bash_profile on your Mac running OSX Snow Leopard to run Android ADB from any folder and without ./

You must be logged in to post a comment.