这里说的不是设置变量给bash/shell来用, 而是给程序使用, 好比, chromium自36版之后, 就再也不内置google api keys, 官方文档(http://www.chromium.org/developers/how-tos/api-keys)说明你打包的时候没有添加key的话, 能够在runtime添加, 好比在系统的环境变量里添加进去.shell
Providing Keys at Runtime If you prefer, you can build a Chromium binary (or use a pre-built Chromium binary) without API keys baked in, and instead provide them at runtime. To do so, set the environment variables GOOGLE_API_KEY, GOOGLE_DEFAULT_CLIENT_ID and GOOGLE_DEFAULT_CLIENT_SECRET to your "API key", "Client ID" and "Client secret" values respectively.
至于key哪来的请自行google, 咱们不去申请key的话, 仍是拿来主义:api
export GOOGLE_API_KEY="AIzaSyCkfPOPZXDKNn8hhgu3JrA62wIgC93d44k" export GOOGLE_DEFAULT_CLIENT_ID="811574891467.apps.googleusercontent.com" export GOOGLE_DEFAULT_CLIENT_SECRET="kdloedMFGdGla2P1zacGjAQh"
关于如何在mac上设置环境变量, 有这么一篇雄文: http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-terminal-only/, 我通常是直接编辑~/.bash_profile
文件, 此次不生效了, 改来改去都没用, 因而换关键词, yosemite/el captain下如何设置环境变量, 马上就有答案了:http://stackoverflow.com/questions/25385934/setting-environment-variables-via-launchd-conf-no-longer-works-in-os-x-yosemitebash
头两个答案均可以, 第一个是恢复了setenv VARIABLENAME=VALUE
这种语法, 第二个是直接在一个文件里编辑, 而后使之生效, 我直接用了第二种, 由于文本随时可编辑, 可查看app
1, Create an environment.plist file in ~/Library/LaunchAgents/
with this content:ide
<?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 GOOGLE_API_KEY AIzaSyCkfPOPZXDKNn8hhgu3JrA62wIgC93d44k launchctl setenv GOOGLE_DEFAULT_CLIENT_ID 811574891467.apps.googleusercontent.com launchctl setenv GOOGLE_DEFAULT_CLIENT_SECRET kdloedMFGdGla2P1zacGjAQh </string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
2, You can add many launchctl commands inside the <string></string>
block.可见, 咱们只须要在string
标签里写须要的内容就好了, 本例是一系列google api keys.ui
3, The plist will activate after system reboot. You can also use launchctl load ~/Library/LaunchAgents/environment.plist
to launch it immediately.this