ANDROID_HOME
Ubuntu
Environment Variables
Android Development
Path Configuration

How to set ANDROID_HOME path in ubuntu?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Setting ANDROID_HOME on Ubuntu means telling your shell and build tools where the Android SDK lives. The job is simple once you know the SDK directory, but it is easy to get wrong if you edit the wrong shell profile, forget to update PATH, or point the variable at Android Studio instead of the SDK itself.

Find the SDK Directory First

On Ubuntu, a common SDK location is:

text
/home/your-user/Android/Sdk

Verify it before exporting anything.

bash
ls ~/Android/Sdk

You should see directories such as platform-tools, build-tools, and cmdline-tools or similar SDK components.

Add ANDROID_HOME to Your Shell Profile

If you use bash, edit ~/.bashrc. If you use zsh, edit ~/.zshrc.

Example for bash:

bash
nano ~/.bashrc

Add these lines:

bash
1export ANDROID_HOME="$HOME/Android/Sdk"
2export PATH="$ANDROID_HOME/platform-tools:$PATH"
3export PATH="$ANDROID_HOME/emulator:$PATH"
4export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$PATH"

Then reload the file:

bash
source ~/.bashrc

For zsh, the same exports go into ~/.zshrc, followed by:

bash
source ~/.zshrc

Verify the Configuration

After reloading the shell, confirm the variable and tools resolve correctly.

bash
echo "$ANDROID_HOME"
which adb
adb version

If adb is not found, the variable may be correct while your PATH is still incomplete.

What to Put in PATH

The most useful SDK subdirectories are:

  • 'platform-tools for adb'
  • 'emulator for emulator commands'
  • 'cmdline-tools/latest/bin for SDK manager tools'

Some setups also need tools or older command-line directories, but newer SDK layouts typically rely on cmdline-tools.

Some older build setups still look for ANDROID_HOME. Some tools also recognize related SDK-root variables. If you are dealing with mixed tooling or old scripts, it can be practical to keep the SDK root consistent across those environments rather than relying on one assumption.

The key operational rule is: all Android tools in your environment should resolve to the same SDK installation.

CI and Non-Interactive Shells

If the variable is needed in CI, Docker, or system services, editing ~/.bashrc may not be enough because non-interactive shells do not always load the same profile files. In those cases, define the variable explicitly in:

  • the CI environment settings
  • the Dockerfile
  • the service unit or startup script

Example Dockerfile snippet:

dockerfile
ENV ANDROID_HOME=/opt/android-sdk
ENV PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin:$PATH

That keeps automated builds independent from local shell startup behavior.

Common Failure Modes

Typical mistakes include:

  • setting ANDROID_HOME to the Android Studio app path instead of the SDK path
  • editing ~/.profile while your shell reads ~/.bashrc or ~/.zshrc
  • forgetting to reload the shell configuration
  • adding only ANDROID_HOME but not updating PATH

If Gradle or adb still cannot find the SDK, verify the exact shell file being loaded:

bash
echo "$SHELL"
ps -p $$ -o comm=

Common Pitfalls

The biggest mistake is pointing ANDROID_HOME at the wrong directory. Another is assuming that exporting the variable alone is enough without adding platform-tools or cmdline-tools to PATH. Teams also often edit one shell profile and then test in a different shell, which makes the setup look randomly broken. In CI, relying on interactive-shell profile files is another frequent source of confusion.

Summary

  • Set ANDROID_HOME to the actual Android SDK directory, not the IDE directory.
  • Add key SDK subdirectories to PATH, especially platform-tools and command-line tools.
  • Edit the correct shell startup file for your shell and reload it.
  • Verify with echo, which adb, and adb version.
  • In CI or Docker, define the variable explicitly instead of relying on interactive shell profiles.

Course illustration
Course illustration

All Rights Reserved.