I'm looking for a way to have some environment variables set for every application.

From what I read there are multiple possible files such as ~/.profile, ~/bash_profile, ~/.zshenv etc. But everything I can find seems to be about setting environment variables for the shell (i.e.: when I open a Terminal). Famously macOS changed from having default bash to default zsh.

I want to set these environment variables for my whole login, even GUI apps which are not (obviously) associated with any shell session.

I have, of course, tried ~/.profile but this did not work. On Linux this would have been executed when I login, not just when I open a Terminal. Is there any such similar configuration file on macOS (11.3).

Apologies if this is trivial, I'm very experienced with Linux but very new to macOS.

  • See stackoverflow.com/a/36161817/151019
    – mmmmmm
    Jul 27, 2021 at 11:33
  • @mmmmmm that's painfully obscure. Thank's for finding it for me. Jul 27, 2021 at 11:36
  • There used to be a much easier way - but Apple considered it a security hole - which it could be - The idea is to only have things inside the apps control chnage the app e.g. by changing its preferences
    – mmmmmm
    Jul 27, 2021 at 11:38

1 Answer 1

launchctl setenv key value

To make this take effect at login automatically, create a launch agent to execute this at RunAtLoad.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .