where is $PATH set in xcode?

前端 未结 9 724
半阙折子戏
半阙折子戏 2020-12-03 07:16

It looks like xcode\'s $PATH environment setting is different from my user shell environment.

Where does xcode get the $PATH setting from and what\'s the best way t

相关标签:
9条回答
  • 2020-12-03 07:23

    Xcode doesn't look at your shell path environment.

    Have a look at NSProcessInfo; and do an NSLog to see what comes up.

    If you want a path to apply to all graphical programs you need to set up the ~/.MacOSX/environment.plist. as described.

    The recommended way to set the environmen variables are actually in /etc/paths and etc/paths.d although these are also not picked up by Xcode.

    I asked about this here.

    0 讨论(0)
  • 2020-12-03 07:23

    This is an update for later versions of macOS and Xcode as things have altered. This is with Xcode 11.0 and macOS 10.14

    The biggest issue is that ~/.MacOSX/environment.plist does not get read now.

    1. Build Settings

    This means that if in the build you need the PATH set, e.g. for external builds and they run executables there is no simple solution. /etc/paths does not seem to be read either.

    The solution is as in @GhostLyrics answer to add the PATH variable in Build Settings. However as noted in comments Xcode will not just use that value but it puts its own values before that. Also it does a straight textual substitution and so you need to also add the separator that PATH uses i.e. the : (colon). The value I have added is :opt/local/bin I also found that you can only do this for a target and not at the project level.

    1. Run Shell Script

    This is the simple case as in this answer

    PATH=${PATH}:/opt/local/bin
    

    or whatever inside the script content.

    Alternatively put this change in your non login shell starter file e.g. ~/.bashrc ~/.zshrc

    1. Running the executable

    This is done in the Schema in the Run portion. Set PATH in the environment variables as stated in answers here. Note I have not tried this and I am not certain how much of the PATH needs setting.

    0 讨论(0)
  • 2020-12-03 07:27

    The easiest solution is to add the PATH variable in Xcode.

    PATH=${PATH}:/usr/local/bin

    0 讨论(0)
  • 2020-12-03 07:28

    If you are talking specifically about the executable search path environment variable named PATH, then there are a few places that it is set:

    • In your shell settings if it is a command line tool. Depending on your shell, this could be ~/.cshrc, ~/.profile, ~/.bash_profile, etc.
    • In the environment.plist file that was mentioned earlier.
    • If you are in a debugger, then it is whatever gdb uses. I believe that gdb will read commands from ~/.gdbinit if it exists.
    • XCode lets you set environment variables within the Info page for executables.
    0 讨论(0)
  • 2020-12-03 07:28

    Try opening your xcode project from the terminal, this worked for me: open some.xcodeproj

    Instead of opening xcode and then loading the project or double clicking on it.

    I know... silly

    0 讨论(0)
  • 2020-12-03 07:31

    Nothing was working for me in XCode 7.
    You need to set the PATH variable in XCode schemes.

    Found the solution at: Where to set environment variables for app?

    0 讨论(0)
提交回复
热议问题