There are different solutions regarding the definition of environment variables that are stored in the launchd
process, namely over at StackOverflow and Superuser. How do these solutions differ?
Defining environment variables with launchd/launchctl
environment-variableslaunchd
Related Question
- MacOS – OS X Yosemite permanent environement variables
- MacOS – Shell set environment variables for command
- Interaction between profiles of Terminal.app and environment variables
- MacOS – Setting environment variables (TEXINPUTS) in El Capitan
- Setting GUI Visible Environment Variables with OS Catalina
- Why do the environment variables keep getting wiped out in Mac OS Catalina
- MacOS – Reproducing execution launchd execution environment
Best Answer
For the sake of clarity, I will refer to this solution as the static solution, the second solution as the dynamic solution, and finally this one as the launch agent solution. I am going to compare the static and dynamic solution with the launch agent one, respectively.
The static solution involves the editing of
/etc/launchd.conf
. This has the advantage, as with the launch agent solution, that the variables are set right at the login. Disadvantages are that/etc/launchd.conf
does not allow for things like variable substitution and such stuff (at least that is my guess, maybe it is feasible),/etc/launchd.conf
to pull the static solution off, with the other one you can put all files at accessible places, e.g. the launch agent in~/Library/LaunchAgents/
,The dynamic solution is similar to the launch agent solution. Its disadvantage is that the variables are not available right after login, you first need to (re-)define them. To combine the dynamic solution with the other, imagine you wanted to set the variable
FOO
to the content of the variableBAR
. You would fire up a shell, say the bash, and typeThen
FOO
would be available in all applications started after this definition, and would also be defined right after the next login.