I want to set some environment variables in my Mac.
I was hoping to do that by creating a small bash script file inside
and then restart my machine.
Is this the correct way to add environment variable?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.Sign up to join this community
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.