Add Environment Variable to PATH
Solution 1:
Your variables are out of order. You cannot set a variable based on other variables defined after it.
Set the commands in your ~/.bash_profile
to the following:
export BRANCH_NAME=dev
export DEV_CLI="/path/to/cli/$BRANCH_NAME/bin"
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$DEV_CLI:$PATH"
Why this is happening...
- When you open a new shell, it reads
~/.bash_profile
- It sets a
PATH
environment variable with other environment variables that aren't defined yet (DEV_CLI
andBRANCH_NAME
) - The environment variables are then defined
- You re-source
~/.bash_profile
and sets thePATH
again, this time with defined variables
It's important to note that this has nothing to do with the Apple "eco system," per se. This is a Bash issue, and more generally a shell issue; you would literally have this problem whether you were on Apple, BSD, Linux, Unix and even Windows.