Mac OS X: Set / Change $PATH Variable

I need to add dev tools (such as JDK and friends) to my PATH. How do I change $PATH variable in OS X 10.8.x? Where does $PATH get set in OS X 10.8 Mountain Lion?

Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 5m
$PATH is nothing but an environment variable on Linux, OS X, Unix-like operating systems, and Microsoft Windows. You can specify a set of directories where executable programs are located using $PATH. The $PATH variable is specified as a list of directory names separated by colon (:) characters. To print the current settings, open the Terminal and then type:

echo "$PATH"


printf "%s\n" $PATH

Sample outputs:

Fig.01: Displaying the current $PATH settings using echo / printf on OS X

Fig.01: Displaying the current $PATH settings using echo / printf on OS X

OS X: Change your PATH environment variable

You can add path to any one of the following method:

  1. $HOME/.bash_profile file using export syntax.
  2. /etc/paths.d directory.

Method #1: $HOME/.bash_profile file

The syntax is as follows:

export PATH=$PATH:/new/dir/location1
export PATH=$PATH:/new/dir1:/dir2:/dir/path/no3

In this example, add /usr/local/sbin/modemZapp/ directory to $PATH variable. Edit the file $HOME/.bash_profile, enter:
vi $HOME/.bash_profile
vi ~/.bash_profile
Append the following export command:

export PATH=$PATH:/usr/local/sbin/modemZapp

Save and close the file. To apply changes immedialty enter:
source $HOME/.bash_profile
. $HOME/.bash_profile
Finally, verify your new path settings, enter:
echo $PATH
Sample outputs:


Method #2: /etc/paths.d directory

Apple recommends the path_helper tool to generate the PATH variable i.e. helper for constructing PATH environment variable. From the man page:

The path_helper utility reads the contents of the files in the directories /etc/paths.d and /etc/manpaths.d and appends their contents to the PATH and MANPATH environment variables respectively.

(The MANPATH environment variable will not be modified unless it is already set in the environment.)

Files in these directories should contain one path element per line.

Prior to reading these directories, default PATH and MANPATH values are obtained from the files /etc/paths and /etc/manpaths respectively.

To list existing path, enter:
ls -l /etc/paths.d/
Sample outputs:

total 16
-rw-r--r--  1 root  wheel  13 Sep 28  2012 40-XQuartz

You can use the cat command to see path settings in 40-XQuartz:
cat /etc/paths.d/40-XQuartz
Sample outputs:


To set /usr/local/sbin/modemZapp to $PATH, enter:

sudo -s 'echo "/usr/local/sbin/modemZapp" > /etc/paths.d/zmodemapp'

OR use vi text editor as follows to create /etc/paths.d/zmodemapp file:
sudo vi /etc/paths.d/zmodemapp
and append the following text:


Save and close the file. You need to reboot the system. Alternatively, you can close and reopen the Terminal app to see new $PATH changes.


  1. Use $HOME/.bash_profile file when you need to generate the PATH variable for a single user account.
  2. Use /etc/paths.d/ directory via the path_helper tool to generate the PATH variable for all user accounts on the system. This method only works on OS X Leopard and higher.
See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 11 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
11 comments… add one
  • Kip Oct 6, 2014 @ 22:03

    thank you for this.

    to append multiple executables in one group, e.g ‘modemZapp2’:
    sudo -s ‘echo “/usr/local/sbin/modemZapp2” >> /etc/paths.d/zmodemapp’

  • Evgheni Dec 8, 2014 @ 20:23

    Thank you for your useful article! It helped me a lot!

  • fred Feb 14, 2015 @ 11:17

    I cannot get this to work. You write “Save and close the file”. How do I do this please?

  • fred Feb 14, 2015 @ 11:57

    I would like to be able to use gcc to compile a file.
    I see gcc-4.0 and gcc-4.2 in /Developer/usr/bin/
    echo “$PATH” gives me this:
    If I need to set the path also to /Developer/usr/bin/ where my gcc is (I mean I guess I have to do that, not even sure) I am kind of lost. I append this:
    vi $HOME/.bash_profile
    Then I see in he Terminal many line breaks with ~ in front, the cursor is before all these breaks and at the bottom I read “”~/.bash_profile” [New File]” (in my firs attempts it was written “INSERT”).
    If I paste “export PATH=$PATH:/Developer/usr/bin” there, I don’t know how to go further. If I then paste “source $HOME/.bash_profile” after, I get a mess: I had to re-install xcode everytime I messed up with the Terminal which kept on scrolling and scrolling with error messages.

  • fred Feb 14, 2015 @ 11:59

    Actually as soon as I paste “export PATH=$PATH:/Developer/usr/bin”, he word “INSERT” comes up at the bottom replacing ”~/.bash_profile” [New File]”
    So I guess from now on I should save my new bash_profile, bu I do not know how.

  • fred Feb 14, 2015 @ 20:16

    I got it to work. gcc never worked, but g++ did.
    Now the ./a.out command form the script I want to create is not working. Nerverending story. FIle not found no matter where my source file is.

  • Biniam Mar 2, 2015 @ 10:36

    Thank you!

  • Bhujosam Jun 30, 2015 @ 4:39

    When I did echo “$PATH”, I got

    In my .bash_profile file, I have put
    export PATH

    But, when ever I execute a command, I need to give the full path in the command. For example,
    when I take update in SVN. The command should be “svn update” but in my case i need to give “/usr/local/bin/svn update”. It happens for me in every command.
    FYI: I am using OS X Yosemite, 10.10.3

    Is there anything I need to change in resolving this issue ? Thanks in advance.

    • John D.Rockefeller Feb 10, 2017 @ 21:18

      The reason why this is happening is because you are not pointing your “$PATH” to a folder with ONLY Mach-O 64-bit executable x86_64. In order to do this, please follow this tutorial: Long story short, to make for example an executable file from a C file “.c”, use the terminal tool xcrun with clang as an argument followed by the name of your “.c” file…This will look something like xcrun clang helloworld.c. This in turn will generate the desired “Mach-O 64-bit executable x86_64”. The file will look something like: a.out (“The file is called ‘a’ because it is the default name if given no parameters for such”). Now you can take this “a.out” file and rename it to whatever you want your command to be when you are calling it from terminal. Now after renaming your file, put it in a folder where ONLY Mach-O 64-bit executable x86_64 will be located and put this folder in your “$PATH” using any of the options listed in this article and finito!. Now you can call your file with the desired named from the terminal.

  • Avijeet Jul 19, 2017 @ 3:34

    Conclusion : If you want additional values to your path for all users, you just have to create a new file in /etc/paths.d and put, on per line, additional paths that are required.

    Conclusion : Specific roles taken up from time to time by users could need different environment settings. Ex – Dev role by the administrator could need the XAMP stack, and access to executing Apache, MySQL and PHP. Though Apache and PHP come built-in along with Yosemite, their bin directories are not set in the PATH variable.
    Hence, we can have .bash_profile_dev in the HOME of the administrator, with all the PATH settings and command line conveniences for starting / stopping servers, etc as the need arises. This can be executed whenever the user needs to change their role, by running . .bash_profile_dev or source .bash_profile_dev at the command prompt. This avoids the unneeded increase in PATH at other times.
    Also having them as .bash_* makes it explicit that they are bash scripts.

    Conclusion : Individual .bash_profile in $HOME is the best place for specifying aliases used by each.

    If you want to change the order of directories in PATH, you have to clean it before calling path_helper. This can be done by altering /etc/profile.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum