OS X reads builtin version of ruby

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.

On 6/25/07, Herb F. [email protected] 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.

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.

Do you have a non-native Python installed?

When I followed the HiveLogic directions for installing Ruby (found
here:
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.

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

times.


Posted via 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.

Herb F. [email protected] 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.

“Richard” == Richard L. [email protected] 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:

    Check for bash rc and source it. All changes to to that file.

    [[ -f ~/.bashrc ]] && . ~/.bashrc

    This line basically ensures that contents of .bashrc are also loaded
    when you
    have a normal login shell.

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

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

The bash manual page at:

http://www.gnu.org/software/bash/manual/bashref.html#SEC65

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

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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs