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.

  1. Open Terminal
  2. Open the .bash_profile file:
$ nano ~/.bash_profile
  1. 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
  1. Save the changes and exit the editor.
  2. 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.

Leave a Comment