# OS X reads builtin version of ruby

**URL:** <https://www.ruby-forum.com/t/os-x-reads-builtin-version-of-ruby/107715>\
**Category:** Ruby\
**Created:** [June 25, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/os-x-reads-builtin-version-of-ruby/107715 "2007-06-25T17:13:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herb\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ecc23a/32.png) [@Herb\_F](https://www.ruby-forum.com/u/Herb_F)\
**Post date:** [June 25, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/os-x-reads-builtin-version-of-ruby/107715/1 "2007-06-25T17:13:49Z")

</div>

Ok, so i’ve tried to install 1.8.6 in a few ways, the first was building  
it from source and most recently using macports. I’ve added the correct  
lines to both my /etc/profile and ~/.bash\_login. Whenever I reload these  
files manually I get the correct version of ruby by issuing the version  
command. Can anyone help? I searched the forum for my question but had  
difficulty finding an answer. Sorry if this has been asked a million  
times.

---

<div class="post-metadata">

**Author:** ![Herb\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ecc23a/32.png) [@Herb\_F](https://www.ruby-forum.com/u/Herb_F)\
**Post date:** [June 25, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/os-x-reads-builtin-version-of-ruby/107715/2 "2007-06-25T17:21:44Z")

</div>

On 6/25/07, Herb F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ok, so i’ve tried to install 1.8.6 in a few ways, the first was building  
> it from source and most recently using macports. I’ve added the correct  
> lines to both my /etc/profile and ~/.bash\_login. Whenever I reload these  
> files manually I get the correct version of ruby by issuing the version  
> command. Can anyone help? I searched the forum for my question but had  
> difficulty finding an answer. Sorry if this has been asked a million  
> times.

You need to update your PATH in ~/.bashrc. profile/bash\_profile are run  
for  
login shells. Starting a terminal isn’t neessarily going to run a login  
shell.

---

<div class="post-metadata">

**Author:** ![Herb\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ecc23a/32.png) [@Herb\_F](https://www.ruby-forum.com/u/Herb_F)\
**Post date:** [June 25, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/os-x-reads-builtin-version-of-ruby/107715/3 "2007-06-25T17:31:31Z")

</div>

> You need to update your PATH in ~/.bashrc. profile/bash\_profile are run  
> for  
> login shells. Starting a terminal isn’t neessarily going to run a login  
> shell.

Hi, thanks for the quick reply. It still seems to be reading the old  
version of ruby over the new one. I updated .bashrc like you said. Is  
there any way to disable the older version? It seems like its just  
having a conflict choosing between the two.

---

<div class="post-metadata">

**Author:** ![Herb\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ecc23a/32.png) [@Herb\_F](https://www.ruby-forum.com/u/Herb_F)\
**Post date:** [June 25, 2007, 6:32pm UTC](https://www.ruby-forum.com/t/os-x-reads-builtin-version-of-ruby/107715/4 "2007-06-25T18:32:09Z")

</div>

Do you have a non-native Python installed?

When I followed the HiveLogic directions for installing Ruby (found  
here:  
[Dan Benjamin](http://hivelogic.com/narrative/articles/ruby-rails-mongrel-mysql-osx)), I  
found that OS X would find the correct version of Ruby until I quit  
Terminal and re-opened it. The problem, it turned out, was Python: the  
line Python installs in ~/.bash\_profile seemed to be overriding the PATH  
setting in ~/.bash\_login that the HiveLogic article advised.

My solution was to move the Python line from .bash\_profile, and include  
it in .bash\_login. I then deleted .bash\_profile (or rather, moved it to  
.bash\_profile.bad.) My .bash\_login now looks like this:

* * *

## export PATH=“/usr/local/bin:/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/local/mysql/bin:${PATH}” export RUBYOPT=“-rubygems”

which seems to work like a charm. I’m not all that knowledgeable about  
this stuff, though, so you may better off editing .bashrc, as Herbie  
advised.

---

<div class="post-metadata">

**Author:** ![Herb\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ecc23a/32.png) [@Herb\_F](https://www.ruby-forum.com/u/Herb_F)\
**Post date:** [June 25, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/os-x-reads-builtin-version-of-ruby/107715/5 "2007-06-25T20:14:19Z")

</div>

On 25 Jun 2007, at 16:14, Herb F. wrote:

> times.
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

The overkill way would be something like

sudo mv /usr/bin/ruby /usr/bin/ruby-old-1.8.2  
sudo ln -s /usr/local/bin/ruby /usr/bin/ruby # or ln -s /opt/  
local/bin/ruby … if you want to use the one macports installed

BUT you will have to remember to update the link if you want to  
update ruby – and this is a less good solution than getting the path  
right in the first place because you have two things to update  
instead of just one. Getting the path right would involve something like  
export PATH=/usr/local/bin:/usr/local/mysql/bin:/opt/local/bin:/opt/  
local/sbin:$PATH in your .profile

Then again, expediency is the mother of invention.

---

<div class="post-metadata">

**Author:** ![Herb\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ecc23a/32.png) [@Herb\_F](https://www.ruby-forum.com/u/Herb_F)\
**Post date:** [June 25, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/os-x-reads-builtin-version-of-ruby/107715/6 "2007-06-25T23:17:47Z")

</div>

Herb F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ok, so i’ve tried to install 1.8.6 in a few ways, the first was building  
> it from source and most recently using macports. I’ve added the correct  
> lines to both my /etc/profile and ~/.bash\_login. Whenever I reload these  
> files manually I get the correct version of ruby by issuing the version  
> command. Can anyone help? I searched the forum for my question but had  
> difficulty finding an answer. Sorry if this has been asked a million  
> times.

What are you actually saying in order to invoke ruby, and where are you  
invoking it from? The Terminal, for example, is not the same BBEdit.

I can only tell you what I did after installing ruby 1.8.5 in  
/usr/local/bin, which was to edit my .bash\_profile (not my .bash\_login)  
to include this line:

PATH=“/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH”

Here is some output in my terminal:

$ echo $PATH  
/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/bin:/sbin:/usr/bin:  
/usr/sbin  
$ which ruby  
/usr/local/bin/ruby  
$ ruby --version  
ruby 1.8.5 (2006-08-25) [powerpc-darwin8.7.0]  
$ ruby -e ‘puts ENV[“PATH”]’  
/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/bin:/sbin:/usr/bin:  
/usr/sbin

TextMate uses the same shell, so things work there too.

But in BBEdit if I just want to use the Run command, I must start the  
script with an explicit shebang line:

#! /usr/local/bin/ruby

And even then it does not pick up the new PATH. The solution to _that_  
is to edit .MacOSX/environment.plist. You must provide a full, explicit  
PATH value (there is no variable expansion here).

m.

---

<div class="post-metadata">

**Author:** ![Herb\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ecc23a/32.png) [@Herb\_F](https://www.ruby-forum.com/u/Herb_F)\
**Post date:** [June 27, 2007, 4:56am UTC](https://www.ruby-forum.com/t/os-x-reads-builtin-version-of-ruby/107715/7 "2007-06-27T04:56:09Z")

</div>

> > > > > “Richard” == Richard L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

```
Richard> The line Python installs in ~/.bash_profile seemed to be 

```

overriding  
Richard\> the PATH setting in ~/.bash\_login that the HiveLogic  
article  
Richard\> advised.

```
Richard> My solution was to move the Python line from .bash_profile, 

```

and  
Richard\> include it in .bash\_login. I then deleted .bash\_profile  
(or  
Richard\> rather, moved it to .bash\_profile.bad.) My .bash\_login now  
looks  
Richard\> like this:

You should move the contents of ‘.bash\_login’ to ‘.bashrc’

For an interactive login shell (like the one you see in OS X Terminal),  
when  
bash starts up, it looks for the following files (in the order listed)  
and reads  
only the FIRST file it finds (in your case, .bash\_login, since you  
deleted  
.bash\_profile):

```
1. ~/.bash_profile
2. ~/.bash_login
3. ~/.profile (this is mostly for Bourne Shell compatibility)

```

However, a non-login shell will ONLY read ~/.bashrc

You can check this behavior by trying out the experiment listed at the  
bottom of  
this post.

In order to ensure a consistent behavior (e.g. for the shells that you  
open via  
Terminal.app and also for the ones that other applications such as  
BBEdit or  
TextMate open for you), try the following:

1. Move the content of .bash\_login to .bashrc

2. Delete .bash\_login (after moving its contents)

3. Edit a new .bash\_profile to have the following content:

4. Quit Terminal.app and relaunch. Your PATH related changes should be  
effective.

The bash manual page at:

> **[Bash Reference Manual](http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html)**
>
> Bash Reference Manual

has all the gory details which will help you here.

Another good and succinct article explaining the concept is:

[http://jmatrix.net/dao/case/case.jsp?case=7F000001-1C208B0-10C91F4FD67-107](http://jmatrix.net/dao/case/case.jsp?case=7F000001-1C208B0-10C91F4FD67-107)

Hope this helps.

# =================================== EXPERIMENT

As an experiment, try this (first backup your existing files by renaming  
them to  
something like .bash\_login.bkp, .bash\_profile.bkp and .bashrc.bkp):

Step 1: Create a single line .bash\_profile with the content:

```
   echo "bash_profile was read"

```

Step 2: Create a single line .bashrc with the content:

```
   echo "bashrc was read"

```

Step 3: Ensure that you have renamed .bash\_login and no such file exists  
in your  
home directory.

Step 4: Quit the Terminal.app and restart it again (or open a new  
Terminal  
Window). You should see this in the Terminal window:

```
   bash_profile was read

   This indicates that only bash_profile is read on an interactive 

```

login  
terminal.

Step 5: Now enter the following command to start another interactive  
(BUT  
non-login bash shell:

```
   <prompt> $ bash

   You should see the following:

   bashrc was read

```

This indicates that this time around, only .bashrc was read by the  
shell, since  
it determined that it is _not_ a login shell.

Step 6: Revert back all files from the .bkp versions you had created  
earlier.

===============================================================================
