`

Setting environment variables in OS X?

 
阅读更多

stackoverflow.com/questions/135688/setting-environment-variables-in-os-x

 

Bruno is right on track. I've done extensive research and if you want to set variables that are available in all GUI apps, your only option is /etc/launchd.conf

Please note that environment.plist does not work for applications launched via Spotlight. This is documented by Steve Sexton here.

1) Open a terminal prompt

2) Type sudo vi /etc/launchd.conf (note: this file might not yet exist)

3) Put contents like the following into the file

# Set environment variables here so they are available globally to all apps
# (and Terminal), including those launched via Spotlight.
#
# After editing this file run the following command from the terminal to update 
# environment variables globally without needing to reboot.
# NOTE: You will still need to restart the relevant application (including 
# Terminal) to pick up the changes!
# grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
#
# See http://www.digitaledgesw.com/node/31
# and http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/
#
# Note that you must hardcode the paths below, don't use enviroment variables.
# You also need to surround multiple values in quotes, see MAVEN_OPTS example below.
#
setenv JAVA_VERSION 1.6
setenv JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
setenv GROOVY_HOME /Applications/Dev/groovy
setenv GRAILS_HOME /Applications/Dev/grails
setenv NEXUS_HOME /Applications/Dev/nexus/nexus-webapp
setenv JRUBY_HOME /Applications/Dev/jruby

setenv ANT_HOME /Applications/Dev/apache-ant
setenv ANT_OPTS -Xmx512M

setenv MAVEN_OPTS "-Xmx1024M -XX:MaxPermSize=512m"
setenv M2_HOME /Applications/Dev/apache-maven

setenv JMETER_HOME /Applications/Dev/jakarta-jmeter

4) Save your changes in VI and reboot your Mac. Or use the grep/xargs command show in the code comment above.

5) Prove that your variables are working by opening a Terminal window and typing export and you should see your new variables. These will also be available in IntelliJ and other GUI apps you launch via Spotlight.

 

Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan?

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://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/#.VzLvFWYabGl

sudo nano /etc/paths

 

分享到:
评论

相关推荐

    Android.Games.Practical.Programming.By.Example.Quickstart

    Unit 1, Setting up Development Environment, begins by teaching you how to set up an Android development environment on your computer no matter which OS you have. You'll learn how to install Android ...

    Sublime Text 3 (Build 3143)

    Mac: the user's default shell is executed and environmental variables are set in the plugin Python environment Linux: Update X11 selection on clipboard every time selection changes Linux: Improved MOD...

    Using Perl For Web Programming.pdf

    Setting up an Environment for Server-Side Includes H Understanding the Commands H G Understanding Shopping Carts Shopping Cart Using Hidden Fields H Shopping Cart Using HTTP Cookies H G From ...

    python3.6.5参考手册 chm

    Port-Specific Changes: Mac OS X Port-Specific Changes: IRIX Porting to Python 2.6 Acknowledgements What’s New in Python 2.5 PEP 308: Conditional Expressions PEP 309: Partial Function Application...

    EurekaLog_7.5.0.0_Enterprise

    16)..Added: Support for environment variables in project option's paths 17)..Added: Support for relative file paths and environment variables for events and various module paths 18)..Added: Logging ...

    Django 1.0 Website Development.pdf

    Installing Django on UNIX/Linux and Mac OS X 16 Installing a database system 17 Creating your first project 18 Creating an empty project 18 Setting up the database 20 Launching the development ...

    appfuse.tar.gz

    Maven repository (/Users/${username}/.m2/repository on OS X and C:\Documents and Settings\${username}\.m2\repository on Windows). To setup hierarchical projects in Eclipse 3.2+, perform the ...

    Android_Learning_Notes_Part 1.pdf

    Understanding the architecture of Android and setting up the development environment with the Android SDK and Eclipse IDE are crucial steps for any developer looking to create applications for Android...

    Python Cookbook, 2nd Edition

    Counting Pages of PDF Documents on Mac OS X Recipe 2.25. Changing File Attributes on Windows Recipe 2.26. Extracting Text from OpenOffice.org Documents Recipe 2.27. Extracting Text from ...

    php.ini-development

    The PHPRC environment variable. (As of PHP 5.2.0) ; 3. A number of predefined registry keys on Windows (As of PHP 5.2.0) ; 4. Current working directory (except CLI) ; 5. The web server's directory ...

    JIDE Desktop Application Framework(桌面应用框架) 开发员技术手册

    - 支持多种操作系统界面设计标准:Java跨平台、Linux/Gnome、Mac OS X 和 Windows XP。 - Model-View-Controller 架构,简化数据与视图管理。 - 支持GUI和控制台应用程序。 - 与JIDE其他组件(如Docking ...

    ethminer-0.16.0.dev3

    There is an environment var `CUDA_DEVICE_ORDER` which tells the Nvidia CUDA driver how to enumerates the graphic cards. Following values are valid: * FASTEST_FIRST (Default) - causes CUDA to guess...

    计算机网络第六版答案

    Any system that is part of the botnet can automatically scan its environment and propagate by exploiting the vulnerability. An important property of such botnets is that the originator of the botnet ...

    DebugFactory3.zip

    and variables contained in the file being displayed by the editor, and clicking an item in that list displays the relevant location. Functions such as string search and GREP necessary for source code...

    微软内部资料-SQL性能优化2

    The user address space is where application code, global variables, per-thread stacks, and DLL code would reside. The system address space is where the kernel, executive, HAL, boot drivers, page ...

    Springer.The.Developer’s.Guide.to.Debugging.2008.pdf

    8.1.1 Environment Variables . . . . . . . . . 101 8.1.2 Local Installation Dependencies . . . . . . . 102 8.1.3 Current Working Directory Dependency . . . . . . 102 8.1.4 Process ID Dependency . . . ....

    xcode8 关闭控制台不打印不信息的解决方法(图文详解)

    4. 在右侧的“Arguments”(参数)部分,找到“Environment Variables”(环境变量)区域。 5. 点击"+"按钮,添加一个新的环境变量。 6. 输入变量名 `OS_ACTIVITY_MODE`,并将其值设置为 `disable`。 7. 确认设置...

    UNIX环境高级编程英文第三版+源码

    2.3.5 Mac OS X 35 2.3.6 Solaris 35 2.3.7 Other UNIX Systems 35 2.4 Relationship of Standards and Implementations 36 2.5 Limits 36 2.5.1 ISO C Limits 37 2.5.2 POSIX Limits 38 2.5.3 XSI Limits 41 2.5.4 ...

Global site tag (gtag.js) - Google Analytics