0

I need to set environment variables to build an Ionic application, open the terminal and run the command:

export ANDROID_SDK_ROOT=$HOME/Android/Sdk

Without closing the terminal I type echo $ANDROID_SDK_ROOT, and the environment variable is returned perfectly, so I run "source ~/.bash_profile", to update the environment variables. I open and close the terminal and my environment variable is empty! I tried to set it manually by opening the environment variables files, with a text editor but without success.

  • 2
    Sourcing a file does not update *it* from the current environment. – chepner Aug 10 '22 at 14:45
  • Aside from the fact that I don't quite get why you are sourcing .bash_profile, when you run zsh - this by itself already begs for trouble -, I wonder whether you have put this `export` statement into your .bash_profile. Do a `set -x` before sourcing the file, to see what actually happens in it. – user1934428 Aug 11 '22 at 13:11

1 Answers1

1

For macOS 10.15 Catalina and Newer, you need to use a .zshenv file instead of .bash_profile. This is because, by default since Catalina, the terminal uses zsh instead of bash.

Export paths permanently in the following manner: Create .zshenv file:

touch ~/.zshenv
open -a TextEdit.app ~/.zshenv

Type out the export you want to do in this format:

export ANDROID_SDK_ROOT=$HOME/Android/Sdk

and save it. (From this old answer)

Louay Sleman
  • 1,794
  • 2
  • 15
  • 39