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:
Verify it before exporting anything.
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:
Add these lines:
Then reload the file:
For zsh, the same exports go into ~/.zshrc, followed by:
Verify the Configuration
After reloading the shell, confirm the variable and tools resolve correctly.
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-toolsforadb' - '
emulatorfor emulator commands' - '
cmdline-tools/latest/binfor SDK manager tools'
Some setups also need tools or older command-line directories, but newer SDK layouts typically rely on cmdline-tools.
Older Tooling and Related Variables
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:
That keeps automated builds independent from local shell startup behavior.
Common Failure Modes
Typical mistakes include:
- setting
ANDROID_HOMEto the Android Studio app path instead of the SDK path - editing
~/.profilewhile your shell reads~/.bashrcor~/.zshrc - forgetting to reload the shell configuration
- adding only
ANDROID_HOMEbut not updatingPATH
If Gradle or adb still cannot find the SDK, verify the exact shell file being loaded:
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_HOMEto the actual Android SDK directory, not the IDE directory. - Add key SDK subdirectories to
PATH, especiallyplatform-toolsand command-line tools. - Edit the correct shell startup file for your shell and reload it.
- Verify with
echo,which adb, andadb version. - In CI or Docker, define the variable explicitly instead of relying on interactive shell profiles.

