简体   繁体   English

OSX 10.9 Mavericks环境变量:如何设置环境变量

[英]OSX 10.9 Mavericks environment variables: how to set environment variables

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. 如果我将使用export JAVA_HOME=/Library/Java/Home ,它将仅为当前终端选项卡设置JAVA_HOME ,并且在系统重启后我将需要再次执行此操作。

How I can set environment variable globally to make by default? 默认情况下如何全局设置环境变量?

How I can edit variables in $ env list? 如何在$ env列表中编辑变量?

Add an entry to ~/.bash_profile : ~/.bash_profile添加一个条目:

export JAVA_HOME=/Library/Java/Home
  • save it, (or create it if it doesn't exist) 保存它,(如果不存在则创建它)
  • quit Terminal.app 退出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: 这是在我看来添加条目的最佳位置,尽管OS X的明显不同之处在于,由于某种原因而在何处添加环境变量请参阅:

And for a more generalized UNIX overview: 对于更通用的UNIX概述:

You can set environment variables by adding the export commands to various configuration files. 您可以通过将导出命令添加到各种配置文件来设置环境变量。 Eg ~/.profile 例如〜/ .profile

You can find out more about what files can be used to modify your bash environment by reading the bash manual ( man bash ). 您可以通过阅读bash手册( man bash )找到有关可用于修改bash环境的文件的更多信息。 If you're using a different shell then it's probably similar and its man page should contain the same info. 如果您使用的是不同的shell,那么它可能类似,其手册页应该包含相同的信息。 You can also read this answer on unix.stackexchange.com, which has some of these details. 您还可以在unix.stackexchange.com上阅读此答案 ,其中包含一些这些详细信息。

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 . 如果要为整个用户环境(包括GUI应用程序)设置环境变量,我相信您可以使用〜/ .MacOSX / environment.plist来实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM