Setting Environment Variables on Mac OS X

1

1

I'm new to using Mac OS X. From my understanding, it uses Linux under the covers. I have a need to add an environment variable. Currently, whenever I start a terminal window, I've been executing export MY_ENVIRONMENT_VARIABLE=enabled. I would like to automatically do this, system wide, when the machine starts.

How do I do that on Mac OS X? I tried adding the above line to ~/.bashrc via nano without any luck. How should I set this environment variable?

Thank you!

xam developer

Posted 2015-05-01T12:33:11.453

Reputation: 113

2BSD, not Linux. – JdeBP – 2015-05-01T16:08:47.387

Answers

1

To affect system-wide settings, you probably should add:

export MY_ENVIRONMENT_VARIABLE=enabled

to /etc/profile or /etc/bashrc (the latter is sourced from /etc/profile).

OSX uses bash by default for its /bin/sh. However, it does not use "Linux under the covers", but rather is mostly BSD (with some exceptions such as bash).

Here are some related questions/discussion (which suggest OSX-specific places to modify instead, e.g., environment.plist):

Thomas Dickey

Posted 2015-05-01T12:33:11.453

Reputation: 6 891

What do you mean by 'modify /etc/bashrc'. What to put there in modifications?? – IgorGanapolsky – 2015-11-29T16:52:50.293

1@igor You add export MY_ENVIRONMENT_VARIABLE=enabled to /etc/profile or /etc/bashrc – wisbucky – 2016-04-20T18:45:45.707