Setting permanent Android PATHs on Linux

Building a mobile app is not a simple task, not only because a developer must create oodles of efficient code, but also because there is a lot — and I mean A LOT — of settings to be dealt with. In order to launch and use all android-studio tools and libraries we must first consider organizing all related commands so that they won’t throw errors whenever we need them. This short article is a result of my struggles with installing and re-installing Android-studio on different OS, like Linux and Mac OS. As you probably already know, you need an emulator in order to interact with your app in development. But one does not simply install and open an emulator ©. After downloading and installing android-studio and sdk tools, you should correctly set all environment variables, that your emulator and other Android tools will use further on.

These variables are defining paths to Andoid’s Sdk, emulator, tools and platform-tools. There are a number of ways to set them, but I choose to follow these steps:

  1. check your $PATH.

$ echo $PATH

You might be surprised by the length of this basic variable and discover a lot of repeating lines. In case if this variable is messed up and seems to be build in chaotic way, you may reset it to a default value with the following command:

$ export PATH=$(getconf PATH)

Otherwise you may go ahead and add Androids paths to it:

2) Open your text editor

3) Find the .bash_profile file, which is located in the root of your home directory.

4) Add the following lines to .bash_profile after the “User specific environment and startup programs” comment:

export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

5) Make sure that these paths really work! Simply open them in your terminal window and confirm that the contents correspond to the address:

$ cd $HOME/Android/Sdk

If this path is not found, then follow your common sense to find the correct addresses: where is your Sdk(sdk) folder? It probably is inside the Android folder, but double check all the letters and slashes. Where is your tools folder? Most likely it is right inside the Sdk directory, but won’t hurt to check.

6) After making sure that all paths work as they supposed to, save your .bash_profile and reload your profile:

$ source ~/.bash_profile

Now your environment variables are all set and you are good to go.

Full stack developer