MacOS – Set / Change $PATH Variable Command
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_profilefile:
$ nano ~/.bash_profile- To add a new directory to the
$PATH, add the following line:
export PATH=$PATH:/path/to/new/directoryReplace /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_profilefile:
$ source ~/.bash_profileYour new $PATH variable will be set and will persist across terminal sessions.
