Mac OS X中的环境变量 [英] Environment variables in Mac OS X

查看:95
本文介绍了Mac OS X中的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:下面的链接没有完整的答案。必须将路径或变量设置在两个位置(一个用于GUI,一个用于shell)是跛脚。

Update: The link below does not have a complete answer. Having to set the path or variable in two places (one for GUI and one for shell) is lame.

不重复在OS X中设置环境变量?

来自Windows背景,设置和修改环境变量非常简单(只需转到系统属性>高级>环境变量),似乎不是直接在Mac OS 10.5上。大多数引用说我应该更新/ etc / profile或〜/ .profile。那些等同于系统变量和用户变量?例如,我应该在哪里设置我的 JAVA_HOME 变量?

Coming from a Windows background where it's very easy to set and modify environment variables (just go to System Properties > Advanced > Environment Variables), it does not seem to be that straight forward on Mac OS 10.5. Most references say I should update /etc/profile or ~/.profile. Are those the equivalent of System Variables and User Variables? For example, where should I set my JAVA_HOME variable?

编辑:

我想要能够从终端以及像Eclipse这样的应用程序访问变量。此外,我希望我不必重新启动/注销,使其生效。

I want to be able to access the variable from the terminal as well as an app like Eclipse. Also, I hope I don't have to restart/logout to make this take effect.

推荐答案

不需要重复。您可以使用 launchctl setenv 设置launchd(以及子进程,即从Spotlight启动的任何内容)中使用的环境变量。

There's no need for duplication. You can set environment variables used by launchd (and child processes, i.e. anything you start from Spotlight) using launchctl setenv.

例如,如果您想在 .bashrc 中或在以下任何地方设置launchd后的当前路径镜像:

For example, if you want to mirror your current path in launchd after setting it up in .bashrc or wherever:

PATH=whatever:you:want
launchctl setenv PATH $PATH

这篇关于Mac OS X中的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆