Emacs doesn't use macOS's /etc/launchd.conf env variables. I have the following there:

function addToPATH {
    case ":$PATH:" in
        *":$1:"*) :;; # already there
        *) PATH="$1:$PATH";; # or PATH="$PATH:$1"

export JAVA_HOME8=`/usr/libexec/java_home --version 1.8`
export JAVA_HOME9=`/usr/libexec/java_home --version 9`

But when I use getenv in Emacs to see my JAVA_HOME, it's unset. Setting it using setenv in my init file solves my issue, but this is an ugly workaround.

PS: I also set this variable in .zshenv, which I source in .bashrc, which I source in .bash_profile. So I am really confused that Emacs is not picking this up.

  • Many people with OSX use this library to set the path and exec-path: github.com/purcell/exec-path-from-shell I personally prefer to set those variables at the time a process is launched or on a buffer-local basis, but that requires advanced Emacs tinkering with the functions ... To set other environmental variables, you may wish to have a look at the function setenv-internal and set the variable process-environment.
    – lawlist
    Apr 24 '18 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.