---
title: "Setting environment variables via launchd.conf no longer works in OS X Yosemite/"
author: "kaqi"
date: "2016-05-11T16:40:40Z"
tags: []
categories: ["操作系统"]
slug: "setting-environment-variables-via-launchd-conf-no-longer-works-in-os-x-yosemite"
draft: false
lastmod: "2016-05-11T16:40:40Z"
id: 2297507
url: "https://kaqi.iteye.com/blog/2297507"
---

Create an `environment.plist` file in `~/Library/LaunchAgents/` with this content:

```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>my.startup</string>
  <key>ProgramArguments</key>
  <array>
    <string>sh</string>
    <string>-c</string>
    <string>
    launchctl setenv PRODUCTS_PATH /Users/mortimer/Projects/my_products
    launchctl setenv ANDROID_NDK_HOME /Applications/android-ndk
    launchctl setenv PATH $PATH:/Applications/gradle/bin
    </string>

  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>
```

You can add many `launchctl` commands inside the `<string></string>` block.

The `plist` will activate after system reboot. You can also use `launchctl load ~/Library/LaunchAgents/environment.plist` to launch it immediately.

 

 

# [Setting PATH environmental variables in OSX permanently](http://stackoverflow.com/questions/22465332/setting-path-environmental-variables-in-osx-permanently)

[http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/#.VzLvFWYabGl](http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/#.VzLvsWYabGl)

```
sudo nano /etc/paths
```