這裏說的不是設置變量給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