What you've laid out is the proper way to add additional directories to your user's $PATH.
(NOTE: These instructions are for Macs that use the bash shell. As of macOS 10.15 (Catalina), Macs use zsh by default. All the steps below still apply with the exception that the file is ~/.zshrc instead of ~/.bash_profile. If you're unsure which shell you're using you should be able to run the command ps -p $$ to figure it out)
Step 1 - ~/.bash_profile
To start make edits to your ~/.bash_profile adding whatever locations you'd like to have amended to your $PATH.
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
export PATH="/usr/local/opt/openssl/bin:$PATH"
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
Step 2 - source ~/.bash_profile
After making the above edits to this file you can either use the source command or the . notation to "reload" and changes made to this file in your current shell's context.
$ . ~/.bash_profile
-or-
$ source ~/.bash_profile
Step 3 - Evaluate changes
After making the edits and sourcing them you can confirm they had the effect you desired by echoing the contents of the $PATH varible.
$ echo $PATH | tr ':' '\n'
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/opt/X11/bin
/Applications/Wireshark.app/Contents/MacOS
/usr/local/sbin
/Users/smingolelli/bin
/usr/local/opt/go/libexec/bin
/Applications/Visual Studio Code.app/Contents/Resources/app/bin
/Users/smingolelli/projects/kubebuilder/kubebuilder_1.0.5_darwin_amd64/bin/
The order matters, so directories that occur first will be searched first. If a binary lives in multiple places, the first place encountered will be the one that is used.
Also keep in mind that multiple sourcings of this file will have a negative effect of continuing to add the same changes, so it's often the case that you'll want to completely se the $PATH to a consistent known initial state and then amend it with these types of commands:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin"
export PATH="/some/new/dir:$PATH"
Using path_helper
macOS also includes a helper to assistance in the management of your $PATH. It's located here /usr/libexec/path_helper.
So instead of manually crafting your base $PATH as mentioned above you can instead use this snippet to get a known good starting point for your $PATH.
[ -x /usr/libexec/path_helper ] && eval $(/usr/libexec/path_helper -s)
This will take care to initialize $PATH so any directories listed in /etc/paths and /etc/paths.d/ get added automatically.
echo $PATH– user3439894 Apr 25 '19 at 18:04echo $PATHso I could see explicitly and specifically what the result was. Sorry, but I can't help if I'm not given the info I request! – user3439894 Apr 25 '19 at 18:14/Applications/XAMPP/xamppfiles/bin:/usr/local/opt/openssl/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin– alfredopacino Apr 25 '19 at 18:17export PATH="/usr/local/opt/python/libexec/bin:$PATH"to the top of my~/.bash_profilefile and it sourced it properly when reopening Terminal. I'd suggest swapping the first twoexport PATH=and see if that makes any difference. – user3439894 Apr 25 '19 at 18:27~/.bash_profilefile in a hex editor before it was edited per my suggestion I can't say for sure, but sometimes toggling the bit, so to speak, will fix an error. – user3439894 Apr 25 '19 at 19:00~/.zshrcas my Mac usedzshas default shell. – Sumax Aug 18 '22 at 10:37