How to modify $PATH variable in macos high sierra for Unity 2017.1.2f?
In terminal “echo $PATH” returns me /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
while in Unity Environment.GetEnvironmentVariables()["PATH] returns different values: /usr/bin:/bin:/usr/sbin:/sbin
if you didn’t solve this question already then here is a tip:
open terminal → type “open ~/.bash_profile”
see there are lines stating something like
export JAVA_HOME=( actual path here)
export PATH=$PATH: (more path here)
see that PATH is actualy having $PATH inside itself, it means that on the next sourcing (when you type source ~/.bash_profile in terminal) your PATH variable will add everything that stands after “$PATH:” note that paths are separated with “:”
so if you want to MODIFY the whole PATH you should first remove $PATH from the PATH variable then source the paths and use the only paths that you need, for example i have a bash profile that looks like this
export JAVA_HOME=(path)
export ANDROID_HOME=(path)
export PATH=$PATH:$ANDROID_HOME:(path to platform tools for android)
export PATH=$PATH:(path to ninja builder)
export PATH=$PATH:(path to cmake)
so when i source the bash_profile next time, all these paths will be ADDED to the path variable
judging by the path that your variable returns, you have
/usr/local/bin
/usr/bin
/usr/sbin
/sbin
inside your PATH variable
basically if you edit bash_profile you need to source it by typing “source ~/.bash_profile”
I tried it but it’s not working for me.
Only this dirty hack working
Environment.SetEnvironmentVariable(“PATH”, Environment.GetEnvironmentVariables()[“PATH”] + “:FASTLANE_PATH/bin:/usr/local/bin”);
This is an old topic, but it was never properly explained and is a bit outdated, but still valid. Because I lost a few hours on this, let my findings serve other lost souls…
The question remains: where does the terminal gets its paths from? As answered here and throughout the internet, you can specify PATH variable in the custom user profile in the home ~ directory. But some PATH definitions come before the user profile on a global level. This site explains it well: Mastering the path_helper utility of MacOSX (DevelopersCorner.MasteringThePathHelper) - XWiki
Here’s a brief summary (for Big Sur and later?):
The Terminal (zsh, i.e. Z shell) runs /etc/zprofile script on startup.
It runs the binary executable /usr/libexec/path_helper which outputs command to set the PATH variable with all the needed paths, like this:
The executable takes the paths from the /etc/paths file and the /etc/paths.d folder which contains files containing one lines with path.
The executable merges the results so there is no duplication. Note that this prevents you from specifying the order of execution as mentioned in the article.
Most of this is common across all flavors of Unix, but the path_helper is kinda nuts.
The usual appropriate place to add new things to your own personal user account is in your account’s ~/.zsh/.zshrc file. If you’re still using bash instead of zsh, that would be ~/.bashrc or ~/.bashprofile. You could at that time modify the cruft that path_helper resulted.
The problem comes when you’re trying to launch apps without going through a Terminal or SSH shell. You would ideally wrap such programs like this with your own shim script, so that the customizations you want to the path are limited to that use-case, not to the whole sovereign OS experience.
I’m a humble Windows user and all this is new to me And sadly google wasn’t very helpful
At the moment I’m developing a git integration with Unity and hit this brick wall. Calling Process.Start(“git”) works fine, but calling Process.Start(“git”, “lfs locks”); fails as the git executable couldn’t find the git-lfs extension executable. It is installed at /usr/local/bin which is not present in the Unity environment PATH, but it is in the terminal. So I have to manually set the Unity PATH variable so git lfs support works properly.
AIs are generally better at these kinds of things than search engines. Here’s the result from Phind which gives citations for its information.
Phind
To add a directory to the PATH in macOS, you have two main approaches depending on whether you want the change to be temporary or permanent.
Temporary Modification
For a temporary modification that only affects the current terminal session, you can modify the PATH environment variable directly in the terminal. This method is useful if you only need the directory in your PATH for a short period or for testing purposes. Here’s how you can do it:
Open the Terminal app.
Type the following command, replacing /path/to/directory with the actual path of the directory you want to add to the PATH:
export PATH="/path/to/directory:$PATH"
Press Enter. This command prepends the specified directory to the existing PATH for the current session.
Permanent Modification
For a permanent modification that persists across terminal sessions and reboots, you need to add the directory to the PATH in your shell’s configuration file. The process differs slightly depending on whether you’re using Bash or Zsh as your shell.
For Bash (macOS versions before Catalina)
Open Terminal.
Edit your .bash_profile or .bashrc file in your home directory. If the file doesn’t exist, you can create it. Use a text editor like nano:
nano ~/.bash_profile
Add the following line at the end of the file, replacing /path/to/directory with the actual path:
export PATH="/path/to/directory:$PATH"
Save the file and exit the editor (in nano, press Ctrl + X, then Y, then Enter).
Apply the changes by sourcing your .bash_profile:
source ~/.bash_profile
For Zsh (macOS Catalina and later)
Open Terminal.
Edit your .zshrc or .zsh_profile file in your home directory. If the file doesn’t exist, you can create it. Use a text editor like nano:
nano ~/.zshrc
Add the following line at the end of the file, replacing /path/to/directory with the actual path:
export PATH="/path/to/directory:$PATH"
Save the file and exit the editor (in nano, press Ctrl + X, then Y, then Enter).
Apply the changes by sourcing your .zshrc:
source ~/.zshrc
After following these steps, the specified directory will be added to your PATH permanently, allowing you to run executables in that directory from anywhere in the terminal without specifying their full paths.
That was the info I easily got from Google. But you realize that this doesn’t solve the initial or my problem, as Unity doesn’t read PATH from the terminal profile configs.
I tried to ask Phind this: “Why calling git commands from terminal works but it doesn’t work in Unity on MacOS?” this is what it answered (the important bit): "
Phind
3. Check Git Installation Path: If Git is installed but not recognized by Unity, it might be because the path to the Git executable is not included in the system’s PATH environment variable. You can manually add the path to the Git executable to your PATH variable. For example, if Git is installed in /usr/bin, you can add it to your PATH by adding export PATH=$PATH:/usr/bin to your shell profile file (e.g., .bash_profile, .zshrc)
Which again is what most would assume, what Google initially tells you and is wrong as Unity doesn’t read that PATH.
When I asked it about “git lfs” command instead, result was worse as it started imagining random stuff that don’t exist.
Still, when asked about svn (which has the same issue), it said to use this which is correct and something I used before:
sudo launchctl config user path /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
But again it didn’t explain why is this happening…
I’m having the same issues trying to make a script which compiles a React app and copies the built files to the StreamingAssets folder in our Unity project. Unity seems to have a totally different set of environment variables on Mac, unlike on Windows where it seems to work fine.
For my solution, I gathered all possible locations where the git binary could be installed and manually add them on startup to the PATH environment variable:
#if UNITY_EDITOR_OSX
string pathEnvVariable = Environment.GetEnvironmentVariable("PATH").TrimEnd(':', ';'); // : is for OSX, ; is for Windows
// Unity PATH variable by default: /usr/bin:/bin:/usr/sbin:/sbin
// Homebrew spits out binaries at '/usr/local/bin' for Intel or '/opt/homebrew/bin' for ARM.
// MacPorts spits out binaries at '/opt/local/bin' (not tested).
if (!pathEnvVariable.Contains("/usr/local/bin")) {
pathEnvVariable += ":/usr/local/bin";
Environment.SetEnvironmentVariable("PATH", pathEnvVariable);
}
if (!pathEnvVariable.Contains("/opt/homebrew/bin")) {
pathEnvVariable += ":/opt/homebrew/bin";
Environment.SetEnvironmentVariable("PATH", pathEnvVariable);
}
if (!pathEnvVariable.Contains("/opt/local/bin")) {
pathEnvVariable += ":/opt/local/bin";
Environment.SetEnvironmentVariable("PATH", pathEnvVariable);
}
#endif