Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 14, 2010, 06:02 PM   #1
SBR210
macrumors newbie
 
Join Date: Sep 2010
How to set the PATH in Terminal?

As a newbie to Bash and the Terminal, in connection with installing a new version of Ruby and various add-ons, I have been messing around with changing the PATH via various methods I've found on the internet, and trying to add a new directory to my PATH. Unfortunately, I cannot figure out how to set the PATH correctly. Here is what I understand so far:

1. Bash first looks to ".bash_profile" in the home directory for PATH settings.
2. If none, Bash then looks to ".bash_login" for PATH settings.
3. If none, Bash then looks to ".profile".
4. If none, Bash then looks to a system file in "/etc/profile" for default PATH settings.
5. For a new shell after login, Bash looks for a ".bashrc" file.

I cannot find any of the above files (I have Finder set to show hidden files already). Somehow, following some instructions from the internet without really knowing what I was doing over the past week I have set my PATH as follows:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/*******/src:/usr/X11/bin

but I cannot find the file that is setting this PATH. I have tried creating a new ".bash_profile" shell file and putting it in various places such as "/bin" and "/usr/bin" but the file is not being read.

- As a temporary workaround I tried using the command "source .bash_profile" upon login to set the PATH using the .bash_profile file that I created, but it does not work.
- I am able to temporarily alter the path using the command "PATH=/usr/local/bin:$PATH" but this only lasts for an active shell; when I close out and reopen a new shell, it reverts to the default.

So my questions are:
Is it correct that there is a "/etc/profile" somewhere that is setting the default PATH? If so where is it? Should I alter it, or create a new ".bash_profile" somewhere to set the PATH? If not, where is my PATH being set? If I should create a new ".bash_profile", what exactly should go in it?

Thanks in advance for any assistance.
SBR210 is offline   0 Reply With Quote
Old Sep 14, 2010, 06:10 PM   #2
angelwatt
Moderator emeritus
 
angelwatt's Avatar
 
Join Date: Aug 2005
Location: USA
Found with MRoogle
http://forums.macrumors.com/showthread.php?t=315941
http://forums.macrumors.com/showthread.php?t=407157
angelwatt is offline   0 Reply With Quote
Old Sep 15, 2010, 02:27 AM   #3
mmulin
macrumors 6502
 
Join Date: Jun 2006
Quote:
Originally Posted by SBR210 View Post
As a newbie to Bash and the Terminal, in connection with installing a new version of Ruby and various add-ons, I have been messing around with changing the PATH via various methods I've found on the internet, and trying to add a new directory to my PATH. Unfortunately, I cannot figure out how to set the PATH correctly. Here is what I understand so far:

1. Bash first looks to ".bash_profile" in the home directory for PATH settings.
2. If none, Bash then looks to ".bash_login" for PATH settings.
3. If none, Bash then looks to ".profile".
4. If none, Bash then looks to a system file in "/etc/profile" for default PATH settings.
5. For a new shell after login, Bash looks for a ".bashrc" file.

I cannot find any of the above files (I have Finder set to show hidden files already). Somehow, following some instructions from the internet without really knowing what I was doing over the past week I have set my PATH as follows:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/*******/src:/usr/X11/bin

but I cannot find the file that is setting this PATH. I have tried creating a new ".bash_profile" shell file and putting it in various places such as "/bin" and "/usr/bin" but the file is not being read.

- As a temporary workaround I tried using the command "source .bash_profile" upon login to set the PATH using the .bash_profile file that I created, but it does not work.
- I am able to temporarily alter the path using the command "PATH=/usr/local/bin:$PATH" but this only lasts for an active shell; when I close out and reopen a new shell, it reverts to the default.

So my questions are:
Is it correct that there is a "/etc/profile" somewhere that is setting the default PATH? If so where is it? Should I alter it, or create a new ".bash_profile" somewhere to set the PATH? If not, where is my PATH being set? If I should create a new ".bash_profile", what exactly should go in it?

Thanks in advance for any assistance.
The reason, the files are not there, is that in the default installation, everything is sourced from the default profile. To customize, just create the necessary files. I don't recommend messing with the default profile files. They might get over written in future updates and the changes lost.

Just put below in the ~/.profile file. Replace "<directory>" with your directory, the PATH should include. Adding more than one directory, separate them by column ":". This will add the missing directories to the default PATH. There is no need to list the directories which are already in the default PATH. Check those before with "echo $PATH".

PATH=$PATH:<directory> ; export PATH
(i.e. PATH=$PATH:/usr/local/bin:/opt/bin)

One more note. ".profile" & ".bashrc" are essentially the same files. In my system I linked the first to the second to avoid ambiguity.
__________________
the net is vast and infinite
:x1c, pb2400c, 4gs
mmulin is offline   0 Reply With Quote
Old Sep 15, 2010, 09:25 AM   #4
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by mmulin View Post
One more note. ".profile" & ".bashrc" are essentially the same files. In my system I linked the first to the second to avoid ambiguity.
True only if you always use bash from a login shell.

If your ~/.profile is full of stuff to make your interactive experience more pleasant that really doesn't matter to a bash script and will slow down its startup.

http://stefaanlippens.net/bashrc_and_others

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is online now   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
How to get the path of bundle application Tank2005 Mac Programming 2 Jan 20, 2011 02:44 AM
How To Set PassWord For Mobile Terminal iphonetoday Jailbreaks and iOS Hacks 7 Jan 13, 2011 12:59 PM
how to set up aliases in Terminal? beethovengirl Mac Applications and Mac App Store 10 Sep 13, 2010 06:20 PM
how to get the path and url of the temp image ? xiaohuli170 Mac Programming 1 Feb 14, 2009 01:36 AM
How to set the first entry in NSPopUpButton satyam90 Mac Programming 3 Feb 4, 2008 11:24 AM


All times are GMT -5. The time now is 08:49 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC