When you ask your computer to run a program, it needs to be able to find the program's executable files. The PATH is its 'official' list of places to look.
You can have Terminal add locations to your PATH each time you open it. To set this up, you need to create a 'bash profile' ('bash' being the language that Terminal runs in), which Terminal will read each time it launches. The bash profile can list locations that Terminal adds temporarily to the computer's PATH.
These steps show how to do that, in particular for adding Ruby to your PATH after installing it with Homebrew.
-
Open Terminal.
-
Enter
cd ~/
to go to your home folder. (Your Terminal might already be in the home folder, but this just makes sure.) -
Enter
touch .bash_profile
to create your new bash profile file. (It's fine if the file already exists, it won't be overwritten.) -
To open the file for editing, enter
open -e .bash_profile
. Unless you've set a different editor as your default, it will open in TextEdit. -
Paste this line into the file (if there is already anything there, add it on a new line at the end):
export PATH=/path/to/bin:$PATH
Well, not exactly. That's a template for adding any location to your PATH. You must replace
/path/to/bin
with the path to the folder location that you need in your PATH. For instance, to add Ruby 2.6.0 installed by Homebrew, you'd use:export PATH=/usr/local/Cellar/ruby/2.6.0/bin:$PATH
You may need to use Finder to figure out the correct folder location. To jump to a folder like
/usr/local/
in Finder, use the 'Go > Go to Folder' menu option and enter/usr/local/
. -
Save and close the
.bash_profile
file. -
In Terminal, enter
. ~/.bash_profile
to reload the profile without relaunching Terminal. (You can also just close and reopen Terminal.)
You can now forget about the bash profile, at least until you need to change it or add another location to your PATH.