V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaochong
V2EX  ›  macOS

OS X 10.9 自动加载的环境变量在哪设置?/etc/profile 好像不起作用

  •  
  •   xiaochong · 2014-03-25 22:19:11 +08:00 · 6827 次点击
    这是一个创建于 3697 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在/etc/profile 中配置了不起作用,source后只能在shell中使用,gui程序无效,怎么办?
    第 1 条附言  ·  2014-03-26 21:05:20 +08:00
    配置在/etc/launchd.conf可以生效,其它都还要启动shell。
    12 条回复    1970-01-01 08:00:00 +08:00
    Rand01ph
        1
    Rand01ph  
       2014-03-25 22:55:13 +08:00
    OS X中的guy程序会从用户自己的environment.plist文件中获得环境变量
    Rand01ph
        2
    Rand01ph  
       2014-03-25 22:56:21 +08:00   ❤️ 1
    = = 是gui,你也可以试试etc/paths
    yangxin0
        4
    yangxin0  
       2014-03-25 23:17:34 +08:00
    ~/.bashrc里面设置就好了, 每次打开bash就有了哇
    SoloCompany
        5
    SoloCompany  
       2014-03-26 12:33:59 +08:00   ❤️ 2
    我的做法,没有直接编辑 /etc/launchd.conf 毕竟需要 sudo 比较不友好
    我是在 ~/.bash_profile 上加了这几行内容,比如

    ~~~
    ... other script to setup env ...
    launchctl setenv JAVA_HOME "$JAVA_HOME"
    launchctl setenv ENV1 "$ENV1"
    launchctl setenv ENV2 "$ENV2"
    ... ...
    launchctl limit maxfiles 1000000
    ~~~

    我确保每次启动系统都肯定会自动打开 iTerm 的,所以这个脚本就会被执行到,所以里面的 launchctl 指令也都会被执行到了
    winsky027
        6
    winsky027  
       2014-03-26 19:30:32 +08:00
    /etc/bashrc
    mahone3297
        7
    mahone3297  
       2014-04-02 22:52:02 +08:00
    @SoloCompany https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man5/launchd.conf.5.html#//apple_ref/doc/man/5/launchd.conf
    问下,看到这里说,$HOME/.launchd.conf 这个文件也会有作用,一直试,一直无效。。。只有/etc/launchd.conf有效。知道为什么嘛?
    SoloCompany
        8
    SoloCompany  
       2014-04-03 00:54:28 +08:00
    @mahone3297 你看的不仔细啊,就这么点内容下面这么明显的写着 (currently unsupported) 你都看不见


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    FILES
    $HOME/.launchd.conf Your launchd configuration file (currently unsupported).
    /etc/launchd.conf The system's launchd configuration file.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    mahone3297
        9
    mahone3297  
       2014-04-03 11:45:33 +08:00
    @SoloCompany 我擦,原来如此,多谢指导。。。
    居然不支持,那不是变的有点侵入式的设计了。。。污染了系统环境变量。。。
    mahone3297
        10
    mahone3297  
       2014-04-03 11:47:34 +08:00
    @SoloCompany 另外,再请教下。我昨天碰到这个问题,其实我是想设置这个值,就是你上面贴的这里
    launchctl limit maxfiles 1000000
    我放到/etc/launchd.conf中,开机启动后,确实有效果了(launchctl limit maxfiles这样运行,应该是会返回值,确实变大了)。但是我运行ulimit -n,返回仍然是256,到底怎么回事?怎么破?
    launchctl limit maxfiles 1000000和ulimit的区别是什么?请指教。
    SoloCompany
        11
    SoloCompany  
       2014-04-04 00:13:57 +08:00   ❤️ 1
    @mahone3297 我也不是很清楚啊,我改过 ulimit 貌似也没多大帮助,反正以前经常会遇到 socket 无法打开之类的错误后来不知道怎么又好了,我在 ~/.bash_profile 里面把 ulimit -n 10240 也加上了,现在的环境是这样

    $ ulimit -n
    10240

    $ ulimit -a
    core file size (blocks, -c) 0
    data seg size (kbytes, -d) unlimited
    file size (blocks, -f) unlimited
    max locked memory (kbytes, -l) unlimited
    max memory size (kbytes, -m) unlimited
    open files (-n) 10240
    pipe size (512 bytes, -p) 1
    stack size (kbytes, -s) 8192
    cpu time (seconds, -t) unlimited
    max user processes (-u) 709
    virtual memory (kbytes, -v) unlimited
    mahone3297
        12
    mahone3297  
       2014-04-07 19:05:20 +08:00
    @SoloCompany ok.我也在.profile文件里加了,现在ulimit -a输出跟你一致。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1082 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:24 · PVG 06:24 · LAX 15:24 · JFK 18:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.