Correct method to set my PATH on Mojave and later 2020
I find a lot of old and new ideas on the proper way to set up your path on macOS. Some ancient and most likely not relevant today.
I have exported some paths and they are in .bash_profile
When I:
source .bash_profile
I end up with duplicates in my path (how to prevent this?)
To reset my path I have tried:
eval `/usr/libexec/path_helper -s`
Which works well because it pulls any paths from paths.d but for some reason puts the paths I have in .bash_profile at the end instead of the beginning of my path (is this avoidable?)
If I "source .bash_profile" again I end up with duplicates in my path so I attempted to set the system's default path at the beginning of my user's .bash_profile using:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin ; export PATH
But this leaves out the paths in paths.d (if there was a way to add those paths in paths. d here I would be set)
I would like to get the default paths (I think these are Mojave and later Paths with the addition of /usr/local/bin)
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Including whatever is in paths.d which right now is:
/Applications/Wireshark.app/Contents/MacOS
And add any custom paths in user's .bash_profile. I would like those all to stay in order and put even if I run source .bash_profile.
This site says this:
Conclusion
Use $HOME/.bash_profile file when you need to generate the PATH variable for a single user account.
Use /etc/paths.d/ directory via the path_helper tool to generate the PATH variable for all user accounts on the system. This method only works on OS X Leopard and higher.
Is this advice current?
Is the following correct on prefixing your path and appending it?
If you use this syntax:
export PATH=/usr/local/opt/nano/bin:"$PATH" #appends to path instead of prefixing
Whereas:
export PATH=$PATH:/usr/local/opt/nano/bin #prefixes to path instead of appending
And, If the idea is to use paths.d for system wide additions to PATH then the concept of using .profile for exporting paths is deprecated?
Also, I thought that exporting paths in .bash_profile caused them to take precedence. Yet when resetting paths using eval `/usr/libexec/path_helper -s` it puts my .bash_profile paths at the end?!
Hope someone can enlighten me. Thanks!
iMac 27″, macOS 10.14