Where is the default terminal $PATH located on Mac?
MacosBashPathMacos Problem Overview
I have been looking throughout the system but I cannot find it. When I do echo $PATH I get the stuff I added, plus the default path. I do not have a .profile, and I do have a .bashrc, but the default path is not in there. I am looking for it just to know where it is located because all the tutorials explain that its in .profile... but what if you don't have one? Where is it located then? Anybody have any ideas?
Macos Solutions
Solution 1 - Macos
If you do sudo man path_helper
, it talks a bit about how it puts the path together. You might look in /etc/paths
and /etc/paths.d
. I did, and found what I was looking for.
Solution 2 - Macos
Many system-wide settings including PATH
are set in /etc/profile
which is read in by bash
at startup. On Mac OS X this file usually uses path_helper
to set PATH
. This utility in turn reads the information from other system configuration files under /etc
(see path_helper
manpage).
Note that even if you disable the reading of the initialization files by bash (e.g. with command-line options like --noprofile
) it will still inherit the environment of the parent process.
Solution 3 - Macos
If you start at /etc/profile, it should look something like this:
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
It's testing to see if the file exists and if so, executes it. If you execute it by hand, you'll get something like this:
PATH="/usr/bin:/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin"; export PATH;
I believe that's what you're looking for. So it comes from /etc/profile, which in turn calls an executable that sets the path.
Solution 4 - Macos
As mentioned in the accepted answer, the $PATH
is built by first looking into the content of the file /etc/paths
, and then looking into every file in the folder /etc/paths.d
. So, the $PATH
in the pre-installed bash
system installation contains every entry in these files, as well as in other shell types.
However, because in the latest Mac OS versions the default shell is zsh
, I followed a couple of tutorials in which the writer avoided to change the $PATH
for the bash
shell, and simply added new entries to the $PATH
by editing ~/.zshrc
the following way:
export PATH=/path/available/only/for/zsh/shells:$PATH
The above command adds /path/available/only/for/zsh/shells
to the $PATH
, and the added path will only be available in zsh
shells.
I hope this helps someone who, like me, had too many entries in the $PATH
in zsh
shells, and couldn't figure out where they were coming from!
Solution 5 - Macos
The .profile file on Mac is located in your user folder: ~/Users/youruser/ However, the .profile file is hidden. You can press Command+shift+. (command, shift, dot) while on Finder to see them.
Solution 6 - Macos
There's one important fact I only realized today while debugging a problem: the profile settings (.bash_profile
etc.) are only read by login shells. They are not read by the processes that are used to launch your applications.
You launch your applications in diverse ways: click the icon in /Applications
, or type the name in Spotlight search, or click an icon in the Dock ... In all those cases, the application itself (i.e the binary or shell script inside the application) is launched by launchd without any parent shell. Meaning that your profile is not run and that your custom settings (PATH, environment variables ...) will be ignored.
That can cause all sorts of trouble, for example if you setup you environment to use a specific version of Java: your application will not see that and use the "default" java, which will be the one with the highest version number.
In my case, the problem is that my application was crashing when run via the application launcher, but runs fine when run from a terminal window ... The reason was that I had a custom path that included some libraries required by the application, but that was not available when the application was run by the launcher.
The solution I used was to symlink the libraries needed into /usr/local/lib