Android Studio Environment Variables on Mac
Recently, while setting up a React Native Expo project, I needed to set up Android Studio on my M1 Mac. The problem was, while most of the expo documentation is great, this Android Studio setup page was super confusing regarding what to add or edit around environment variables.
So after a little bit of googling (1) (2) I settled on the commands below. They’re just for osX, which, in my case, appears to be running Zsh rather than Bash, but the description includes both (Without testing the Bash version).
Note: These instructions assume you’ve already installed Android Studio.
Most tutorials on this tell you that if you mac uses Bash do one thing, and if it’s Zsh, do another. I’m simply going to say, if you’re unsure, just do both.
First, open a terminal window and run the following command. It should tell you that it can’t find the file. When this works later, you’ll know you’re environment variables are working.
adb
Reminder, the above won’t work. That’s the point for now.
Instructions
Now run the below code in the terminal to open your environment variables file.
For Bash
touch ~/.bash_profile; open ~/.bash_profile
For Zsh
touch ~/.zshrc; open ~/.zshrc
The touch commands above created the required file in the right location, and the open command opens it so you can edit it. You can copy in the code exactly as I have it and it will create and then open it at the same time.
Once in each file, copy in this content and, on the first line, replace the variable in the path to match your setup (or just replace the whole path).
export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/emulator
Close and reopen your terminal.
Once you’ve save the file or files above and closed them, also close terminal and reopen it. There’s commands to refresh the environment variables but I’ve had inconsistent results so I tend to just close and reopen.
Finding your path
If you weren’t sure of your path above or you want to check and replace the whole path, open Android Studio and it’s settings. You’ll see your path in System Settings / Android SDK — Like mine is shown below.
Check it worked
Once you’ve closed and reopened your terminal, try the command from the beginning again to check it works. It should now show you the help instructions for the command.
adb
That’s it!
Thanks…
I also dissect and speculate on design and development.
Digging into subtle details and implications, and exploring broad perspectives and potential paradigm shifts.
Check out my conceptual articles on Substack or find my latest below.
You can also find me on Threads, Bluesky, Mastodon, or X for more diverse posts about ongoing projects.
Leave a Reply