How to edit PATH variable on Mac

If you need to change your PATH variables (or another environment variable, as CLASSPATH) on a Mac OS X, you need to edit a file called .profile located in your home directory. Open a terminal window and type:

open -e ~/.profile

In case you dont have a .profile file, you have to create it:

touch ~/.profile

You have to include a line like this:

export PATH=(path-you-want-to-add):$PATH

For example, lets imagine you want to add the file whatever.jar, located in your Documents folder. You would write:

export PATH=~/Documents/whatever.jar:$PATH

Easy, isnt it?

Bookmark and Share

2 Comments »

RSS feed for comments on this post. TrackBack URI

  1. Thanks a lot! You saved me a lot of time and trouble. In a few lines, you explained what other sites using entire pages had failed to explain.

    Comment by Ali — August 8, 2009 #

  2. This is really nice but i need a bit more help.

    Whenever i type ‘echo $PATH’
    only ever got back my old PATH – which i found impossible to change
    Until now!
    I created a .Profile file in my root directory (Mac:)
    I copied my text edited file **
    Now my echo $PATH reads perfect when I ask Terminal

    My questions are:
    1.If you don’t have a .profile file in the correct place – what are the possible locations that terminal reads and writes to when you type in ‘echo $PATH’ and sudo vi .bash_login (to edit this path)
    OR what file is it reading to show you your $PATH!!! (because i was not able to change a file which reflected a change in $PATH in terminal

    2.What is the root directory? is it MAC: or MAC/users/myname/

    Now i have .profile files everywhere!!!
    I just have big problems understanding what Terminal is editing and showing when you edit the $PATH via the sudo vi .bash_login OR sudo vi .bash_profile (my files were never showing a universally similar PATH)

    Comment by Chris — May 14, 2010 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.