2

I want to set some environment variables in my Mac.

I was hoping to do that by creating a small bash script file inside paths.d and then restart my machine.

Is this the correct way to add environment variable?

  • There's no /etc.d on macOS (or on Linux for that matter). Are you thinking of /etc/rc.d or /etc/profile.d? How do you want this environment variable set and for what purposes (i.e. only in non-login, interactive shells or system wide available to both shells and GUI)? – Allan Nov 1 '18 at 21:25
  • Welcome to Ask Different. - I'll take a stab at answering the most general version of this question. Once that or a couple answers trickle in - I would recommend asking a follow on question - linking here with a specific for instance if you have one package one program in need of configuration this way. Hopefully you don't mean "in bash" or "in zsh" when you stated "in my Mac" above - that might be easily answerable in referencing the man page for whatever shell you wish to have variables and this isn't a general question across all apps - graphical or shell based. – bmike Nov 1 '18 at 21:49
  • Possible duplicate of How do I set environment variables on OS X? – Saaru Lindestøkke Nov 1 '18 at 21:53
  • What kind of application is this for? Normally you would do it in .profile or .bash_profile – John Keates Nov 8 '18 at 15:14
1

In general, there is no one environment on macOS. Not all programs and not even all command line utilities respect the same common environment space.

On OS X - the launch daemon has been around and it spins up a sandboxed / isolated state for each app and each process, so you would edit into the preference / database entry for each process the variables it needs.

The current implementation would be to make a defaults write to write whatever values you want to your "global environment" and than have each program read those preferences as part of their startup or refresh script.

I would encourage you to ask a follow on question since no one really wants to sign variables, they want to write variables so some programs can do something with them. Let's dive into what one or three programs would read what specific variable to do some thing and explore if you are stuck with making a modification to each one or could set up some sort of shared database or call to make those changes effective.

You must log in to answer this question.

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