To set or change the $PATH
variable in macOS, you can modify the .bash_profile
file in your home directory.
- Open Terminal
- Open the
.bash_profile
file:
nano ~/.bash_profile
- To add a new directory to the
$PATH
, add the following line:
export PATH=$PATH:/path/to/new/directory
Replace /path/to/new/directory
with the actual path to the directory you want to add. 4. To modify the existing $PATH
, simply edit the line that sets the $PATH
variable:
export PATH=$PATH:/path/to/directory1:/path/to/directory2
- Save the changes and exit the editor.
- Apply the changes by sourcing the
.bash_profile
file:
source ~/.bash_profile
Your new $PATH
variable will be set and will persist across terminal sessions.