Bruno is right on track. I've done extensive research and if you want to set variables that are available in all GUI applications, your only option is /etc/launchd.conf.

Please note that environment.plist does not work for applications launched via Spotlight. This is documented by Steve Sexton here.

  1. Open a terminal prompt

  2. Type sudo vi /etc/launchd.conf (note: this file might not yet exist)

  3. Put contents like the following into the file

    # Set environment variables here so they are available globally to all apps
    # (and Terminal), including those launched via Spotlight.
    #
    # After editing this file run the following command from the terminal to update
    # environment variables globally without needing to reboot.
    # NOTE: You will still need to restart the relevant application (including
    # Terminal) to pick up the changes!
    # grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
    #
    # See http://www.digitaledgesw.com/node/31
    # and http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/
    #
    # Note that you must hardcode the paths below, don't use environment variables.
    # You also need to surround multiple values in quotes, see MAVEN_OPTS example below.
    #
    setenv JAVA_VERSION 1.6
    setenv JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
    setenv GROOVY_HOME /Applications/Dev/groovy
    setenv GRAILS_HOME /Applications/Dev/grails
    setenv NEXUS_HOME /Applications/Dev/nexus/nexus-webapp
    setenv JRUBY_HOME /Applications/Dev/jruby
    
    setenv ANT_HOME /Applications/Dev/apache-ant
    setenv ANT_OPTS -Xmx512M
    
    setenv MAVEN_OPTS "-Xmx1024M -XX:MaxPermSize=512m"
    setenv M2_HOME /Applications/Dev/apache-maven
    
    setenv JMETER_HOME /Applications/Dev/jakarta-jmeter
    
  4. Save your changes in vi and reboot your Mac. Or use the grep/xargs command which is shown in the code comment above.

  5. Prove that your variables are working by opening a Terminal window and typing export and you should see your new variables. These will also be available in IntelliJ IDEA and other GUI applications you launch via Spotlight.

Answer from Matthew McCullough on Stack Overflow
🌐
Apple Support
support.apple.com › guide › terminal › use-environment-variables-apd382cc5fa-4f58-4449-b20a-41c53c006f8f › mac
Use environment variables in Terminal on Mac - Apple Support
For example, to set the variable PATH to the value /bin:/sbin:/user/bin:/user/sbin:/system/Library/, you would enter the following command in a Terminal window: % PATH=/bin:/sbin:/user/bin:/user/sbin:/system/Library/ export PATH ... When you launch an app from a shell, the app inherits much ...
Top answer
1 of 16
695

Bruno is right on track. I've done extensive research and if you want to set variables that are available in all GUI applications, your only option is /etc/launchd.conf.

Please note that environment.plist does not work for applications launched via Spotlight. This is documented by Steve Sexton here.

  1. Open a terminal prompt

  2. Type sudo vi /etc/launchd.conf (note: this file might not yet exist)

  3. Put contents like the following into the file

    # Set environment variables here so they are available globally to all apps
    # (and Terminal), including those launched via Spotlight.
    #
    # After editing this file run the following command from the terminal to update
    # environment variables globally without needing to reboot.
    # NOTE: You will still need to restart the relevant application (including
    # Terminal) to pick up the changes!
    # grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
    #
    # See http://www.digitaledgesw.com/node/31
    # and http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/
    #
    # Note that you must hardcode the paths below, don't use environment variables.
    # You also need to surround multiple values in quotes, see MAVEN_OPTS example below.
    #
    setenv JAVA_VERSION 1.6
    setenv JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
    setenv GROOVY_HOME /Applications/Dev/groovy
    setenv GRAILS_HOME /Applications/Dev/grails
    setenv NEXUS_HOME /Applications/Dev/nexus/nexus-webapp
    setenv JRUBY_HOME /Applications/Dev/jruby
    
    setenv ANT_HOME /Applications/Dev/apache-ant
    setenv ANT_OPTS -Xmx512M
    
    setenv MAVEN_OPTS "-Xmx1024M -XX:MaxPermSize=512m"
    setenv M2_HOME /Applications/Dev/apache-maven
    
    setenv JMETER_HOME /Applications/Dev/jakarta-jmeter
    
  4. Save your changes in vi and reboot your Mac. Or use the grep/xargs command which is shown in the code comment above.

  5. Prove that your variables are working by opening a Terminal window and typing export and you should see your new variables. These will also be available in IntelliJ IDEA and other GUI applications you launch via Spotlight.

2 of 16
323

Don't expect ~/.launchd.conf to work

The man page for launchctl says that it never worked:

DEPRECATED AND REMOVED FUNCTIONALITY

launchctl no longer has an interactive mode, nor does it accept commands from stdin. The /etc/launchd.conf file is no longer consulted for subcommands to run during early boot time; this functionality was removed for security considerations. While it was documented that $HOME/.launchd.conf would be consulted prior to setting up a user's session, this functionality was never implemented.

How to set the environment for new processes started by Spotlight (without needing to reboot)

You can set the environment used by launchd (and, by extension, anything started from Spotlight) with launchctl setenv. For example to set the path:

launchctl setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

Or if you want to set up your path in .bashrc or similar, then have it mirrored in launchd:

PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
launchctl setenv PATH $PATH

There's no need to reboot though you will need to restart an app if you want it to pick up the changed environment.

This includes any shells already running under Terminal.app, although if you're there you can set the environment more directly, e.g. with export PATH=/opt/local/bin:/opt/local/sbin:$PATH for bash or zsh.

How to keeping changes after a reboot

New method (since 10.10 Yosemite)

Use launchctl config user path /bin:/usr/bin:/mystuff. See man launchctl for more information.

Previous method

The launchctl man page quote at the top of this answer says the feature described here (reading /etc/launchd.conf at boot) was removed for security reasons, so ymmv.

To keep changes after a reboot you can set the environment variables from /etc/launchd.conf, like so:

setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

launchd.conf is executed automatically when you reboot.

If you want these changes to take effect now, you should use this command to reprocess launchd.conf (thanks @mklement for the tip!)

egrep -v '^\s*#' /etc/launchd.conf | launchctl

You can find out more about launchctl and how it loads launchd.conf with the command man launchctl.

Discussions

macos - Setting environment variables osx 12.0.1 - Stack Overflow
I need some help to set environment variables on osX 12.0.1. I tried to edit .bash_profile (it doesnt exist), .zprofile and also a pllist approach. What irritates me, is that % env is not working in More on stackoverflow.com
🌐 stackoverflow.com
macos - How to add permanent environment variable in zsh - Ask Different
You'd need to use launchctl setenv ENV_NAME ENV_VALUE to make it available everywhere. See my other answer for more info. ... In MacOS Monterey, I don't have zshenv under user's dir nor under /etc. Thus I'm using $ echo 'export ENV_VAR=12345' >> ~/.zshrc to inject this environment variable. More on apple.stackexchange.com
🌐 apple.stackexchange.com
Environment variables for GUI apps - Apple Community
I'm looking for a way to set environment variables for GUI applications like IntelliJ that are launched via the dock or Spotlight. I've found launchctl setenv on Google, that only works until the next reboot. The /etc/launchd.conf doesn't exist on my MacOS Monterey. More on discussions.apple.com
🌐 discussions.apple.com
May 12, 2022
How to permanently set environment variables
It’s normal behavior because the command is just for one session. Add it to .zshrc in your home folder if you want it permanently. More on reddit.com
🌐 r/mac
2
0
January 24, 2023
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to set environment variables in macos
How to Set Environment Variables in MacOS | phoenixNAP KB
January 27, 2025 - Note: If you want to display the complete list of shell variables, use the set command. If you want to display the value of any specific environment variable, use the echo command: ... For example, to check the value of the PATH variable which stores a list of directories with executable files, use the echo command: ... Note: Always use the $ prefix when specifying a variable name. The value you assign to a temporary environment variable only lasts until you close the terminal session.
🌐
GitHub
github.com › hschmidt › EnvPane
GitHub - hschmidt/EnvPane: EnvPane - An OS X preference pane for environment variables · GitHub
Release 0.8 is built for macOS 12 "Monterey" and up. It uses code-signed, universal binaries that run on Intel and Apple Silicon processors. It is not notarized by Apple and therefore requires special treatment during installation in order to work around quarantine. EnvPane is a preference pane for macOS that lets you set environment variables for all applications, both GUI and terminal.
Starred by 825 users
Forked by 55 users
Languages   Objective-C 89.9% | C 10.1%
Find elsewhere
🌐
Medium
mamk2118.medium.com › setting-up-environment-variables-in-macos-mojave-and-mac-os-catalina-27ea1bb032f3
Setting up Environment Variables in macOS Big Sur, macOS Mojave, macOS Catalina, macOS Big Sur, macOS Monterey, macOS Ventura and macOS Sonoma | by Mk | Medium
June 11, 2024 - Setting up Environment Variables in macOS Big Sur, macOS Mojave, macOS Catalina, macOS Big Sur, macOS Monterey, macOS Ventura and macOS Sonoma Please note that starting with macOS Catalina (hence …
🌐
nixCraft
cyberciti.biz › nixcraft › howto › macos › how to set or change $path variable on macos/mac os x
MacOS - Set / Change $PATH Variable Command - nixCraft
January 28, 2025 - Use the /etc/paths.d/ directory or folder via the path_helper command tool to generate the PATH variable for all user accounts on the system. This method only works on OS X Leopard and higher macOS version. See the following manual pages using the help command or man command on your macOS / OS X machine: $ man bash $ man path_helper $ help export · Customize the bash shell environments from the Linux shell scripting wiki.
🌐
Apple Community
discussions.apple.com › thread › 253877043
Environment variables for GUI apps - Apple Community
May 12, 2022 - It runs a shell script in ~/.bin which for itself calls launchctl setenv <VARIABLE_NAME> <VALUE> When MacOS boots and I log in, it loads the agent and the environment variable is set.
🌐
Reddit
reddit.com › r/mac › how to permanently set environment variables
r/mac on Reddit: How to permanently set environment variables
January 24, 2023 -

I installed nvm on my MacBook, however once I open a new terminal I cannot call it via any nvm/node/npm command.

I always need to enter this into the console first:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

That's not the normal behavior is it? And is there any way to avoid it?

Top answer
1 of 16
406

First, one thing to recognize about OS X is that it is built on Unix. This is where the .bash_profile comes in. When you start the Terminal app in OS X you get a bash shell by default. The bash shell comes from Unix and when it loads it runs the .bash_profile script. You can modify this script for your user to change your settings. This file is located at:

~/.bash_profile

Update for Mavericks

OS X Mavericks does not use the environment.plist - at least not for OS X windows applications. You can use the launchd configuration for windowed applications. The .bash_profile is still supported since that is part of the bash shell used in Terminal.

Lion and Mountain Lion Only

OS X windowed applications receive environment variables from the your environment.plist file. This is likely what you mean by the ".plist" file. This file is located at:

~/.MacOSX/environment.plist

If you make a change to your environment.plist file then OS X windows applications, including the Terminal app, will have those environment variables set. Any environment variable you set in your .bash_profile will only affect your bash shells.

Generally I only set variables in my .bash_profile file and don't change the .plist file (or launchd file on Mavericks). Most OS X windowed applications don't need any custom environment. Only when an application actually needs a specific environment variable do I change the environment.plist (or launchd file on Mavericks).

It sounds like what you want is to change the environment.plist file, rather than the .bash_profile.

One last thing, if you look for those files, I think you will not find them. If I recall correctly, they were not on my initial install of Lion.

Edit: Here are some instructions for creating a plist file.

  1. Open Xcode
  2. Select File -> New -> New File...
  3. Under Mac OS X select Resources
  4. Choose a plist file
  5. Follow the rest of the prompts

To edit the file, you can Control-click to get a menu and select Add Row. You then can add a key value pair. For environment variables, the key is the environment variable name and the value is the actual value for that environment variable.

Once the plist file is created you can open it with Xcode to modify it anytime you wish.

2 of 16
227

Your .profile or .bash_profile are simply files that are present in your "home" folder. If you open a Finder window and click your account name in the Favorites pane, you won't see them. If you open a Terminal window and type ls to list files you still won't see them. However, you can find them by using ls -a in the terminal. Or if you open your favorite text editor (say TextEdit since it comes with OS X) and do File->Open and then press Command+Shift+. and click on your account name (home folder) you will see them as well. If you do not see them, then you can create one in your favorite text editor.

Now, adding environment variables is relatively straightforward and remarkably similar to windows conceptually. In your .profile just add, one per line, the variable name and its value as follows:

export JAVA_HOME=/Library/Java/Home
export JRE_HOME=/Library/Java/Home

etc.

If you are modifying your "PATH" variable, be sure to include the system's default PATH that was already set for you:

export PATH=$PATH:/path/to/my/stuff

Now here is the quirky part, you can either open a new Terminal window to have the new variables take effect, or you will need to type .profile or .bash_profile to reload the file and have the contents be applied to your current Terminal's environment.

You can check that your changes took effect using the "set" command in your Terminal. Just type set (or set | more if you prefer a paginated list) and be sure what you added to the file is there.

As for adding environment variables to GUI apps, that is normally not necessary and I'd like to hear more about what you are specifically trying to do to better give you an answer for it.

🌐
OS X Daily
osxdaily.com › 2015 › 07 › 28 › set-enviornment-variables-mac-os-x
Where to Set Environment Variables on Mac
December 21, 2021 - Thus you can add zsh environmental variables by modifying that file with nano, vim, etc, or by using echo like so: ... Because the Mac defaults to using bash shell, you can set environmental variables in the user directories .bash_profile, for an active user account the path to that file is locate at:
🌐
Reddit
reddit.com › r/macos › add system-wide environment-variables in macos ventura
r/MacOS on Reddit: Add system-wide environment-variables in MacOS Ventura
April 19, 2023 -

I tried multiple things like adding variables to a plist-file or adjusting /etc/paths, but I didn't figure out how to add system-wide environment-variables in MacOS Ventura.

I switched over to MacOS from Linux and the PATH-variable has a different value in my shell vs. from outside of the shell.

I notice this issue especially in Kitty. This is expected (as stated by the author), if some of the env-variables are different in the shell vs. in the system.

Top answer
1 of 2
2
I have an answer, but I have to preface it with bad news: This approach does not seem to bet working for PATH specifically, at least on Sonoma (macOS 14). I'm here because I found this thread while looking for solutions. BUT, it does work for every other environment variable. Here's what I've got: As you've noticed, your shell (and apps launched from the shell) have the environment variable values specified in your .zshrcfile, because the shell processes that file on startup. However, app launched any other way (e.g. from Finder) don't get those settings. You can use the launchctl command to specify session-wide environment variable values, which finder-launched apps will inherit. Here's an example of using it from a shell script I have: # Set environment variables /bin/launchctl setenv TEXINPUTS ":/Users/andersoe/academics/tools/LaTeX/packages/:/Library/Frameworks/R.framework/Resources/share/texmf/tex/latex/" /bin/launchctl setenv BIBINPUTS ":/Users/andersoe/academics/generated_bibfiles:/Users/andersoe/academics/research/bibfiles/". Note that this will not change the environment for any currently-running program, only what's inherited by apps launched from Finder after you make the change. You can check these values with a corresponding /bin/launchctl getenv . Now, the annoying part. These changes are not persistent across sessions (e.g. logging out, rebooting, etc.) . You have to re-do it every time. There is not, as far as I know, any quick convenient place to put a shell script where it will be automatically run for every session. The best way I know of is this PITA: Make a shell script that actually sets the variables. Mine is called mac_env_setup.zsh, and it looks like what I put up above. Use Script Editor to write a one-line AppleScript that calls the shell script. Mine is called "setup_wrapper.app" and it reads do shell script "/Users/andersoe/personal/macOS_setup/mac_env_setup.zsh". Then, critically, you save this as an "application" file format (not script, script bundle, etc.). Finally, you go into System Settings -> General -> Login Items, hit the "+" at the bottom of the "Open at Login" list, and then you can select your new "app" that runs your AppleScript that runs your shell script that sets your environment variables. Now, unlike, say .zshrc or .xinitrc or what have you, this is not guaranteed to be evaluated before any other program starts. AFAIK, the order in which Login Items and background tasks are started is not guaranteed, so any automatically-started apps may run with the default, un-customized environment variables. That might go for interactively-started applications as well, if you happen to be really quick and unlucky about starting them, but I've never had an issue. Anything I start after it's "done logging in" seems to always have inherited my newly-set variables. Finally, if you're interested, I have another layer of nonsense wrapped around this, an Ansible playbook (with a template file and an awk script on the side) that generates / updates my mac_env_setup.zsh, runs it, and checks whether or not my setup_wrapper.app is in the login items. (It does not generate or update the setup_wrapper.app script, or configure it as a login item, unfortunately, but it does fetch the list of what's configured and tell you whether or not the app is on it.) I'll post that here or e-mail it to you or whatever, if you want it.
2 of 2
1
It should be in your .zshrc file in your home directory.
🌐
TecAdmin
tecadmin.net › setting-up-the-environment-variables-in-macos
Setting Up the Environment Variables in MacOS – TecAdmin
April 26, 2025 - Since the latest macOS uses the Zsh shell, So we can add the environment variables to the ~/.zshrc or ~/.zshenv file for the current user. For example, to create the JAVA_HOME environment variable and also update PATH to include JAVA_HOME. Edit ~/.zshenv and add the following values; ~/.zshevn export JAVA_HOME=$(/usr/libexec/java_home -v11) export PATH="$JAVA_HOME/bin:$PATH" The first line is setting the JAVA_HOME environment variable and the second command is prefixing the Java bin directory to the PATH environment variable.
🌐
Configu
configu.com › home › setting env variables in windows, linux & macos: beginner’s guide
Setting Env Variables in Windows, Linux & MacOS: Beginner’s Guide - Configu
March 13, 2025 - To set an environment variable for the current terminal session, use: ... Note: This variable will be lost once you close the terminal. To make an environment variable persistent, add it to the ~/.bash_profile file (for Bash users) or ~/.zshrc (for Zsh users, the default shell in macOS Catalina and later).
🌐
Medium
youngstone89.medium.com › setting-up-environment-variables-in-mac-os-28e5941c771c
Setting up Environment Variables in Mac OS | by 김영석 | Medium
March 19, 2022 - Temporary Variable is gone now. ... For permanent setting, you need to understand where to put the “export” script. Here in this practice, you are going to edit “.bash_profile” file under your home directory. ... For experiment, I am going to add a test directory to the PATH environment variable.
🌐
Apple
support.apple.com › en-ca › guide › terminal › apd382cc5fa-4f58-4449-b20a-41c53c006f8f › mac
Use environment variables in Terminal on Mac - Apple Support (CA)
For example, to set the variable PATH to the value /bin:/sbin:/user/bin:/user/sbin:/system/Library/, you would enter the following command in a Terminal window: % PATH=/bin:/sbin:/user/bin:/user/sbin:/system/Library/ export PATH ... When you launch an app from a shell, the app inherits much ...