Is there anything in Zsh like .bash_profile?

Yes, it’s called ~/.zshenv.

Here’s how I have $JAVA_HOME set in ~/.zshenv:

export JAVA_HOME="$(/usr/libexec/java_home)"

Keep in mind, however, that zsh is not bash, so just ’cause you have to source your .bash_profile every time you open a terminal does not mean that you have to do that with zsh. With zsh, I only have to re-source my ~/.zshenv when I make changes to it, and then only for terminals which are already open: new terminals should have already sourced my new and improved ~/.zshenv.

NOTE

I often find it helpful, when trying to determine which of my zsh startup files I should place things in to consult zsh startup files.

A newer version of the documentation for startup files can be found here.

Leave a Comment