MacOS – Set / Change $PATH Variable Command By Vivek Gite Published: 2013-08-25 · Archived: 2026-04-05 21:56:36 UTC 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 or latest version of macOS? Tutorial details Difficulty level Easy Root privileges No Requirements macOS terminal Category Linux shell scripting Prerequisites Apple macOS/OS X with bash OS compatibility BSD • Linux • macOS • OS X • Unix Est. reading time 3 minutes $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. MacOS Print $PATH Settings To print the current settings, open the Terminal application and then printf command or echo command echo "$PATH" OR https://www.cyberciti.biz/faq/appleosx-bash-unix-change-set-path-environment-variable/ Page 1 of 4 printf "%s\n" $PATH Here is what I see Fig.01: Displaying the current $PATH settings using echo / printf on OS X macOS (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 to set or change $PATH under macOS 1. Open the Terminal app on macOS. 2. The syntax is as follows using the export command to add to the PATH on macOS: export PATH="$PATH:/new/dir/location1" export PATH="$PATH:/new/dir1:/dir2:/dir/path/no3" 3. In this example, add the /usr/local/sbin/modemZapp/ directory to $PATH variable. Edit the file $HOME/.bash_profile, enter: $ vi $HOME/.bash_profile OR $ nano ~/.bash_profile 4. Append the following export command: export PATH="$PATH:/usr/local/sbin/modemZapp" 5. Save and close the file when using vim/vi as a text editor by pressing the Esc, type :wq and press the [Enter] key. Then, to apply changes immediately enter the following source command: $ source $HOME/.bash_profile https://www.cyberciti.biz/faq/appleosx-bash-unix-change-set-path-environment-variable/ Page 2 of 4 OR $ . $HOME/.bash_profile 6. Finally, verify your new path settings, enter: $ echo "$PATH" Sample outputs: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/sbin/modemZapp 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 try the ls command. For example: $ 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: /opt/X11/bin 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: https://www.cyberciti.biz/faq/appleosx-bash-unix-change-set-path-environment-variable/ Page 3 of 4 /usr/local/sbin/modemZapp 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. For instance: echo "$PATH" You can show sorted path as follows: echo "${PATH//:/$'\n'}" | sort Conclusion MacOS set or Change $PATH settings using any one of the following method as per your needs: 1. Use the .bash_profile file when you need to generate the PATH variable for a single user account with Bash. 2. Use the /etc/paths.d/ directory or folder via the path_helper command tool to generate the PATH variable for all user accounts on the system. This method only works on OS X Leopard and higher macOS version. See the following manual pages using the help command or man command on your macOS / OS X machine: $ man bash $ man path_helper $ help export See also: Customize the bash shell environments from the Linux shell scripting wiki. $PATH variable UNIX: Set Environment Variable 🥺 Was this helpful? Please add a comment to show your appreciation or feedback. Vivek Gite is an expert IT Consultant with over 25 years of experience, specializing in Linux and open source solutions. He writes about Linux, macOS, Unix, IT, programming, infosec, and open source. Follow his work via RSS feed. Source: https://www.cyberciti.biz/faq/appleosx-bash-unix-change-set-path-environment-variable/ https://www.cyberciti.biz/faq/appleosx-bash-unix-change-set-path-environment-variable/ Page 4 of 4