3

How I can EXPORT environment variable not just for one tab but for all system?

If i will use export JAVA_HOME=/Library/Java/Home it will set JAVA_HOME only for current terminal tab and after system restart I will need do it one more time.

How I can set environment variable globally to make by default?

How I can edit variables in $ env list?

Lugaru
  • 1,430
  • 3
  • 25
  • 38

2 Answers2

4

Add an entry to ~/.bash_profile:

export JAVA_HOME=/Library/Java/Home
  • save it, (or create it if it doesn't exist)
  • quit Terminal.app
  • re-launch and you're in business.

This is the best place to add the entry in my opinion, although for the distinct differences on OS X of where to add environment variables specifically for one reason or another see:

And for a more generalized UNIX overview:

Community
  • 1
  • 1
l'L'l
  • 44,951
  • 10
  • 95
  • 146
0

You can set environment variables by adding the export commands to various configuration files. E.g. ~/.profile

You can find out more about what files can be used to modify your bash environment by reading the bash manual (man bash). If you're using a different shell then it's probably similar and its man page should contain the same info. You can also read this answer on unix.stackexchange.com, which has some of these details.

If you want to set environment variables for your entire user environment, including GUI applications, I believe you can do that using ~/.MacOSX/environment.plist.

Community
  • 1
  • 1
bames53
  • 86,085
  • 15
  • 179
  • 244
  • Is this specific to each individual user, or all users? – l'L'l Aug 06 '14 at 07:46
  • @l'L'l it depends on what file you put the configuration in. You can set it for the whole system, for the user, or just for all of the user's shells. Setting users' shell config files is the most common and easiest. – bames53 Aug 06 '14 at 08:01