miércoles, 6 de junio de 2012

How to define system variable in Mac OS

Another tricky business....
We all know how to define a system variable in Mac OS we just do:

set MY_VAR=varcontent
Now the down side of this is that when you close the console ( or the tab console), or just switch tabs the variable doesn't exists any more right????


Well you are free to google the explanation for that ( is not to hard to see though).
Any way here is how you should do it if you want the variable to survive you console:

+ Go you your home path
+ With you favorite text editor change (or create) the file ".profiles"
+ In there add you variable

And presto!!!!!
From now on the variable/s listed there will be available in each console you open (only for your user of course).

1 comentario:

  1. Actually environment variables defined this way will not be visible to processes launched using Spotlight/Finder - only processes launched from Terminal will be able to use the variables defined in .profile.

    But if you want to set a System variable visible to all applications no matter how you launch - you can set them in /etc/launchd.conf

    E.g.
    setenv M2_HOME /usr/share/maven
    setenv MAVEN_OPTS -Dfile.encoding=UTF-8

    Now both IntelliJ IDEA, Eclipse and commandline will use the same settings no matter if I launch them from command line or click the icon in /Applications

    /Flemming

    ResponderEliminar