Bash (the Bourne Again SHell) is an interactive shell, which responds to user typed commands with actions.
When Bash starts up, it executes the commands in a variety of 'dot' files, including ~/.bash_profile.
This file also registers environmental variables, such as PATH, which contains a colon-delimited list of directories that the shell searches through when you enter a command.
The file is just shell commands. It is typically used to change prompts, set environment variables, and define shell procedures. Traditionally, the file
.profileis used for this purpose, but bash has so many extensions that it needs its own startup file for users that want to put bashisms in startup files.
If you have both
~/.profileand~/.bash_profilethen the~/.profilewill not be sourced when Terminal.app starts.
Make sure that the file ~/.profile contains the line source ~/.bashrc. If it doesn't, add it to the end of that file, save it, then restart terminal.
This file is loaded before Terminal loads your shell environment and contains all the startup configuration and preferences for your command line interface. Within it you can change your terminal prompt, change the colors of text, add aliases to functions you use all the time, and so much more.
When Bash complains that a command can't be found, it is saying that it does not understand the command, because it does not know how to action it.
Alternatively, it might know how to action it, but the linked application is old and lacking the abilities of one which you have since installed yourself.
Adding a binary to the PATH variable associated with your user profile is simple:
- Open the
.bash_profileconfiguration file, which Bash loads when it starts up - Register the correct path of the binary or application against the
PATHvariable, which Bash searches through when actioning commands - Close and save the
.bash_profileconfiguration file, to apply the changes - Activate your changes
- Output the
$PATHvariable, to check that it includes the correct path
In MacOS command-line terminology, the tilde symbol (~) refers to your home directory, e.g /Users/Joe.
$ nano ~/.bash_profile
2. Register the correct path of the binary or application against the PATH variable, which Bash searches through when actioning commands
You can either add the path to a specific binary, or the path to a folders of binaries.
For example, this points the mysql command to the copy of mysql that ships with MAMP Pro (bash mysql... -> /Applications/MAMP/Library/bin/mysql ...):
export PATH="/Applications/MAMP/Library/bin/mysql"
While adding an entire folder of binaries also exposes other commands, such as mysqladmin, which also ship with MAMP Pro:
export PATH="/Applications/MAMP/Library/bin:$PATH"
Note that running export ... directly in Terminal doesn't update either the .profile nor the .bash_profile (at least in my experience).
CONTROL+X, Y, ENTER
$ source ~/.bash_profile
$ echo $PATH