如何在Yosemite中设置环境变量

时间:2022-04-27 22:43:39

This question has been asked before but the solutions assume that you are acquainted with OS X, unfortunately I'm not, so please bear with me. I would like to use qmake from the terminal command. With Yosemite, I'm not able to find an easy way to do it. The solution is suggested here but I can't figure out how to use it. The solution is as follows

之前已经问过这个问题,但解决方案假设您熟悉OS X,不幸的是我不是,所以请耐心等待。我想从终端命令使用qmake。对优胜美地来说,我找不到一个简单的方法。这里建议解决方案,但我无法弄清楚如何使用它。解决方案如下

In previous releases of OS X (Mavericks, Mountain Lion, Lion, ...), environment variables are configured in the /etc/launchd.conf file. As of OS X Yosemite, this is no longer working. To configure environment variables, you can do the following

在以前版本的OS X(Mavericks,Mountain Lion,Lion,...)中,环境变量在/etc/launchd.conf文件中配置。从OS X优胜美地开始,这已经不再适用了。要配置环境变量,您可以执行以下操作

$ nano ~/Library/LaunchAgents/my.startup.plist

$ nano~ / Library / LaunchAgents / my.startup.plist

my.startup.plist

<?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 $VARIABLE_NAME $VARIABLE_VALUE</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

In my case, the path to qmake is /Users/XXXX/Qt/5.4/clang_64/bin, what should I do so that the qmake will be recognized in the terminal command?

在我的例子中,qmake的路径是/Users/XXXX/Qt/5.4/clang_64/bin,我该怎么办才能在终端命令中识别qmake?

1 个解决方案

#1


Terminal sessions use the shell. You only should modify shell environment variables, there is no need to reconfigure GUI programs.

终端会话使用shell。您只应该修改shell环境变量,不需要重新配置GUI程序。

Also, I don't suppose the .plist offers a way to extend a preexisting variable.

此外,我不认为.plist提供了一种扩展预先存在的变量的方法。

You could use ~/.profile:

你可以使用〜/ .profile:

export PATH=$PATH:~XXXX/Qt/5.4/clang_64/bin

If Qt offers a more canonical method of installation, that would probably be preferable, though.

如果Qt提供了一种更规范的安装方法,那么这可能会更好。


If you literally just want the command qmake to work, without really installing anything, just do

如果你只是想让命令qmake工作,而没有真正安装任何东西,那就去做吧

sudo ln -s ~/Qt/5.4/clang_64/bin/qmake /usr/local/bin

#1


Terminal sessions use the shell. You only should modify shell environment variables, there is no need to reconfigure GUI programs.

终端会话使用shell。您只应该修改shell环境变量,不需要重新配置GUI程序。

Also, I don't suppose the .plist offers a way to extend a preexisting variable.

此外,我不认为.plist提供了一种扩展预先存在的变量的方法。

You could use ~/.profile:

你可以使用〜/ .profile:

export PATH=$PATH:~XXXX/Qt/5.4/clang_64/bin

If Qt offers a more canonical method of installation, that would probably be preferable, though.

如果Qt提供了一种更规范的安装方法,那么这可能会更好。


If you literally just want the command qmake to work, without really installing anything, just do

如果你只是想让命令qmake工作,而没有真正安装任何东西,那就去做吧

sudo ln -s ~/Qt/5.4/clang_64/bin/qmake /usr/local/bin