Mac OS X 10.9 - setting permanent environment variables

前端 未结 5 1947
执念已碎
执念已碎 2020-12-01 04:09

How do I set a permanent environment variable (i.e. one that does not need exporting every time I start a new Terminal session) in Mac OS X 10.9? I\'ve found a number of ans

相关标签:
5条回答
  • 2020-12-01 04:37

    Drop the $(...) bit, which would attempt to execute the command within the brackets and set $MULE_HOME to whatever it produces. In your case /opt/mule-standalone-3.4.0 is not an executable, hence the error you are getting.

    export MULE_HOME=/opt/mule-standalone-3.4.0
    

    and use ~/.bashrc not ~/.bash_profile.

    EDIT: It seems opinion is that you should set environment variables in your ~/.bash_profile script, and not ~/.bashrc script.

    0 讨论(0)
  • 2020-12-01 04:42

    It seems that Apple keeps changing how to do this. And it's all about context. One way does not necessarily work when another does. I needed it to work in an IDE, and neither of the bash files mention here (Linux style) did that. The current way for GUI apps to respect this on a permanent basis is SUPER convoluted compared to Windows and Linux!

    In a nutshell, you have write a huge pile of ugly XML into a plist file to run some bash. That goes into your "launch agents" directory, i.e. ~/Library/LaunchAgents/my.startup.plist. Here's another Stack Exchange thread on the subject:

    https://apple.stackexchange.com/questions/106355/setting-the-system-wide-path-environment-variable-in-mavericks

    That gives you a full copy & paste which you can tweak to set your specific variable.

    0 讨论(0)
  • 2020-12-01 04:44

    Just did this really easy and quick. First create a ~/.bash_profile from terminal:

    touch ~/.bash_profile
    

    then

    open -a TextEdit.app ~/.bash_profile
    

    add

    export TOMCAT_HOME=/Library/Tomcat/Home
    

    Save document in TextEdit and you are done.

    0 讨论(0)
  • 2020-12-01 04:48

    You can put your export statement in ~/.bashrc

    0 讨论(0)
  • 2020-12-01 04:59

    Alternatively, you can also add the following command to your .bash_profile if you want your environment variables to be visible by graphic applications. In Mac OS X, graphic applications do not inherit your .bash_profile config :

    launchctl setenv MYPATH myvar
    
    0 讨论(0)
提交回复
热议问题