Online poker bonus Casino game Amoxicillin Company Online Jobs Buy cialis now Buy cheap cialis Discount viagra Free Hotel Quick payday loan Rent Bonus casino Cheapest airline tickets Online pharmacy valium Carisoprodol Car insurance comparison Cheapest airline ticket Florida auto insurance Scholarships and grants Cipro Phone Keflex You tube Respiratory therapy Terbinafine Cheap xenical Pharmacies Buy phentermine Nolvadex Tramadol on line X ray technician Clindamycin Dental schools Zero Nicotine Tramadol cod Physical therapist Cheapest viagra Duromine Trade Youtube Send flowers Business travel Duromine (Brand Ionamin) Zolpidem Bingo Tenuate Adult dating Fioricet online Commodity trading Buy acomplia Diovan Servers Smash repair Zithromax antibiotic Football prediction Generic viagra cheap Overnight tramadol Debt loan 
RSS

Adding a New Location to your $PATH Variable within Terminal

Thu, Apr 10, 2008

Adv. Tips

    By: Wayne Dixon

With Mac OS X being based on BSD Unix and being UNIX 03 Compliant you have many of the same features of Linux. One of those features is the ‘shell’ or command line interface, commonly known as Terminal. The default shell for Terminal is bash. You can read all about the Bourne Again Shell (BASH) here on Wikipedia.

One aspect of bash is the ability to set defaults for each Terminal session. This is done from your ~/.bash_login file. You can set many options within this file, including Java environment variables and almost any setting you can think of. One of the most important is the PATH variable.

The PATH Variable tells the system where to look for applications. So, if you were to try and run a Unix command, ‘top’ for instance, the shell would have to know where to look for it. If the application is not within the default locations, it’ll say it cannot find it.

Let’s take a look at what a PATH statement within a .bash_login file looks like:

PATH=”/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:$PATH”

Let’s break this down. The first part, “PATH” tells the shell to set the variable PATH to what follows. Each path is separated by a colon. Much like a comma separated value file, the colon in this case is the delimiter for each path. So /usr/bin/, /bin/, /usr/local/bin, and usr/X11/bin are each individual paths to possible application locations.

The $PATH variable specifies to include any default PATH locations. It’s also used to append additional locations onto the PATH variable.

To see what your current $PATH variable is, go to Terminal by either using spotlight to find it or by going to Your Applications -> Utilities -> Terminal application. Once Terminal loads, type “echo $PATH”. This will display your current $PATH Variable.

Now, if you need to add a new search location you will have to do a few things in order to get this to stay across all of your Terminal sessions. From within Terminal follow these steps:

  1. Type in cd ~. This will bring you to your home directory.
  2. Type sudo vi .bash_login
  3. Type in your root password
  4. You might see a screen that looks like this:
  5. Terminal-New-Bash.login-file .
  6. Type i for Insert
  7. If your file is new, type in PATH=$PATH:/path/to/look/for/new/apps/:. If you already have items in your PATH=… statement just append the “:/path/to/look/for/new/apps/:” to the end of your PATH statement
  8. Hit Escape to stop editing
  9. Type :wq (this will write the file and then quit)
  10. While still within Terminal , type exit
  11. Close Terminal
  12. Open up Terminal again
  13. Type in echo $PATH to verify that the path has been saved. If not, try it again.

Those are the basics of adding a new location to search for apps within Terminal. It’s not something that will come up all the time, but it’s a good thing to know in case it ever does.

If you like it, Share It:
  • TwitThis
  • StumbleUpon
  • Facebook
  • Reddit
  • Digg
  • del.icio.us
  • Technorati
  • Google Bookmarks
  • Mixx
  • NewsVine
  • Propeller
  • LinkedIn
  • MySpace

Related Posts

This post was written by:

Wayne Dixon - who has written 154 posts on Macgasm.


Contact the author

4 Responses to “Adding a New Location to your $PATH Variable within Terminal”

  1. Columbia Says:

    As this file is a user file, sudo is not needed for this change of $PATH.
    Step 7 is a bit misleading because there should always be something in your $PATH variable. /: at the end is not needed.
    To not confuse people who are not familiar with Terminal, you should add “Press Enter” at the end of step 9. and 10.

    Reply

  2. Columbia Says:

    As this file is a user file, sudo is not needed for this change of $PATH.
    Step 7 is a bit misleading because there should always be something in your $PATH variable. /: at the end is not needed.
    To not confuse people who are not familiar with Terminal, you should add “Press Enter” at the end of step 9. and 10.

    Reply


Leave a Reply

Additional comments powered by BackType