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 to append to the search path?
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 to append to the search path?
if you're writing a Run Shell Script build phase, you can just do:
PATH=${PATH}:/opt/local/bin
or whatever inside the script content.
PATH=${PATH}:/usr/local/var/rbenv/shims
–
Bernice There's some confusion in these answers, as some of them are trying to solve the $PATH
for the built executable being run by Xcode. But the question is about Xcode, implying that it's about the build process itself.
For example, in a Build Phase Run Script step that runs an executable installed by Homebrew. It's not a good idea to hard-code the build process to include a path that is specific to one build machine (New macOS versions come out, new developers join the team, etc.)
The problem has multiple layers:
$PATH
in bashrc
/zshrc
/profile
takes effect on shell sessions, but not in macOS applicationsTo solve this, you can set the PATH for applications using:
sudo launchctl config user path "$PATH"
You will then need to restart your machine for the change to take effect. You will need to run this again if you change your $PATH
.
(This came from a comment on GitHub.)
$PATH
, and replaces it with its own sanitized valueThis is solved by changing a User Default. This probably has some risk, since Xcode does this sanitization to ensure that its own build tools are used, and if you have executables with the same name in other places, they might be run instead. Caveat emptor!
defaults write com.apple.dt.Xcode UseSanitizedBuildSystemEnvironment -bool NO
And it looks like this gets reset on every restart of macOS, so be prepared to issue this command every time you restart.
(This part came from this answer.)
sudo launchctl config user path "$PATH"
. Otherwise it may break the path variable. –
Qp This applies for OSX 10.7 and earlier ONLY.
XCode gets its environment variables the same way as other OS X processes, from ~/.MacOSX/environment.plist.
Check developer.apple.com/qa/qa2001/qa1067.html for details on how to set things.
In Xcode 5 you can add your PATH as a variable to either a target or the project settings.
+
sign on the top of the pagePATH
and add your preferred value (e.g. /usr/local/bin
for a default install of homebrew. /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
, Xcode will actually set it to /Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
. This is unfortunate if you want your PATH to override Xcode's, but actually is a good solution if you just want to add /usr/local/bin
or some other directory to the PATH. –
Gamely If you are talking specifically about the executable search path environment variable named PATH, then there are a few places that it is set:
~/.cshrc
, ~/.profile
, ~/.bash_profile
, etc.environment.plist
file that was mentioned earlier.gdb
uses. I believe that gdb will read commands from ~/.gdbinit
if it exists.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.
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.
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
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.
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.
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?
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
© 2022 - 2024 — McMap. All rights reserved.
sudo ln -s /opt/homebrew/bin/{watchman,node} /usr/local/bin
– Philadelphia