Overwhelmingly Geek™

Bits, bytes and signal noise from Shaon Diwakar

Adding to $PATH in MacOSX 10.5 (Leopard)

with 6 comments

After installing postgresql on my Mac, I realised that the installation package didn’t automatically take care of adding the “/Library/PostgreSQL/8.3/bin” directory to the $PATH variable.

Even after some googling I failed to find an easy way to edit the global bash shell path on 10.5. With some digging around, I discovered the quickest way to get things into your $PATH variable is to leverage the path_helper utility, located in “/usr/libexec/path_helper”. Here is what I did in Terminal.app:


1. echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
2. su -
3. cd /etc/paths.d/
4. ls -lha
5. echo "/Library/PostgreSQL/8.3/bin" > Postgresql
6. ^D (CTRL D)

Edit the directory for PostgreSQL (i.e. “/Library/PostgreSQL/8.3/bin” above) to be the location of the app that you wish to add (and give it an appropriate name). Following this, you can start a new shell which should contain the updated $PATH variable; confirm this by repeating step 1 above. If you are interested in learning more about the path_helper application man path_helper.

Written by Shaon Diwakar

September 6, 2008 at 12:09 pm

6 Responses

Subscribe to comments with RSS.

  1. There is an easy way to get it done. Simply add a file to the directory /etc/paths.d

    i.e.
    sudo touch /etc/paths.d/

    then edit that file. the only thing you need to put in it is the path you need. these paths are appended to your PATH environment. if you’re doing this in a terminal window you’ll need to restart the terminal app (or just open a new tab) to see the results of your change.

    cheers!

    connor doyle

    October 15, 2008 at 7:28 am

  2. heh.. nevermind, that exactly what the post says to do!

    connor doyle

    October 15, 2008 at 7:29 am

  3. Thanks for the comments Connor! It would be nice if there were an easier method to edit the path _without_ having root/superuser privileges (aside from constantly editing via echo $PATH = $PATH;/path…

    Shaon Diwakar

    October 15, 2008 at 5:34 pm

  4. Just a little addition: I wanted to add $HOME/bin to the path and being happy to have found out about path_helper thanks to this post, without putting my brain into gear, I typed

    echo “$HOME/bin” > HomeBin

    in place of step six above. Of course, what I didn’t think of was that BASH evaluates variables inside double quotes so what was being put into HomeBin was /var/root/bin (the home of the super user is /var/root).

    To get by this, either edit the file with a text editor such as vi and enter the variable or use single quotes in place of double quotes around the path you want added to $PATH.

    Thanks for the post Shaon!

    Emily

    January 6, 2009 at 9:58 pm

    • My pleasure Emily! I didn’t realise that BASH evaluates variables inside double quotes! You learn something new everyday :-) Thanks for the tip Emily :-)

      Shaon Diwakar

      January 7, 2009 at 8:54 am

      • Use single quotes to prevent variable expansion:

        echo ‘$HOME/bin’ > HomeBin

        dobbs

        September 1, 2009 at 4:50 pm


Leave a Reply