OS X reads builtin version of ruby

Discussion in 'Ruby' started by Herb Fitz, Jun 25, 2007.

  1. Herb Fitz

    Herb Fitz Guest

    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.
     
    Herb Fitz, Jun 25, 2007
    #1
    1. Advertisements

  2. 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.
     
    Herbie Fitzgerald, Jun 25, 2007
    #2
    1. Advertisements

  3. 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:
     
    Richard Lawrence, Jun 25, 2007
    #3

  4. 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.
     
    John Browning, Jun 25, 2007
    #4
  5. 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.

    ===============================================================================
     
    Anupam Sengupta, Jun 27, 2007
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.