0

This is in continuation of my previous two stack-overflow questions echo $JAVA_HOME returns blank in MacOS catalina despite having set it properly in zshrc and Not able to change the JDK in Mac OS using Jenv and looks like I found the issue.

Issue is that I am using .zsh and it works fine for aliases when I add a new alias but when I simply add JAVA_HOME as below line

export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home

It doesn't work on the new terminal but when I explicitly do source source ~/.zshrc then it prints the value of echo $JAVA_HOME and thats the reason of issues mentioned in my previous questions.

I've verified that zsh is my login shell as mentioned in several forums but still why content of .zshrc is not loaded in newly opened terminal?

  • Not really related, but `.zprofile` is better for adding environment variables, as it can be inherited by a non-login interactive shell rather than having to redefined it in `.zshrc`. – chepner Jun 01 '20 at 17:53
  • That said, is your terminal emulator actually configured to start an instance of your login shell? – chepner Jun 01 '20 at 17:55
  • @chepner thanks for your valuable feedback, but I even tried mentioning this in .zprofile but with explicit source it was not working in the new terminal, can you guide me how to fix that and I am not sure how to check what you mentioned in your second comment. –  Jun 02 '20 at 01:18
  • 1
    @es-enthu : For debugging, I would place a `set -x` at the top of `.zshrc` to verify that this file is indeed sourced. It should be, because - unless you have modified the variable `ZDOTDIR` (check its value!) - an **interactive** zsh is supposed to read `$ZDOTDIR/.zshrc`, and a shell attached to a terminal should certainly be interactive. – user1934428 Jun 02 '20 at 08:21
  • @es-enthu : Having said this, it does not matter what your **login** shell is, so for the safe side, verify that you are really running zsh, by doing a `echo $ZSH_VERSION`. – user1934428 Jun 02 '20 at 08:23
  • @user1934428 sorry for late reply `echo $ZSH_VERSION 5.7.1` return and echo $ZDOTDIR returns nothing. –  Jun 02 '20 at 11:12
  • And when you just open a subshell, by typing `zsh`, do you then see your .zshrc be executed (assuming you have put in a `set -x`, as I suggested)? – user1934428 Jun 02 '20 at 13:47
  • @user1934428 yes I see that when I use set -X –  Jun 03 '20 at 05:00
  • 1
    (I hope you mean `-x`, not `-X`). Well, this then means that this file is sourced. This means that you should be able to trace, why `JAVA_HOME` has not been set. Just compare each entry from the `-x` trace to each line in you `.zshrc`. – user1934428 Jun 03 '20 at 06:50
  • ok sure will do –  Jun 03 '20 at 10:19

0 Answers0