INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to tell Terminal which version of Ruby to use?

How to tell Terminal which version of Ruby to use?

How to tell Terminal which version of Ruby to use?

(OP)
Hello,

I have two related questions that I was hoping someone could help out with.

1. I recently installed Ruby 1.9.2 on my Mac (running Snow Leopard 10.6.4) and I haven't been able to figure out how to get Terminal to use the new Ruby as a default, rather than the factory-installed Ruby 1.8.7.  The old Ruby 1.8.7 is located in my ~/usr/bin/ruby directory while the new Ruby 1.9.2 is in ~/usr/local/bin/ruby.  Someone said that I need to put the new version of Ruby's directory in the PATH prior to the old version's directory so that the system looks there first - is this correct?  If so, can anyone provide step by step instructions on how to do this?

2. I've created a new directory but can't seem to figure out the correct way to add that directory to my PATH using the Terminal bash shell.  I tried using the instructions that I found here (http://www.macgasm.net/2008/04/10/adding-a-new-location-to-your-path-variable-within-terminal/) twice but they didn't work for me.  The directory containing my program ("Ruby_Programs") shows up in the PATH but when I try to run "ruby newprogram.rb" from the command line it results in ":ruby: No such file or directory -- newprogram.rb (LoadError)".

Any help would be greatly appreciated.  Here is my current PATH:

$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/*******/src:/usr/X11/bin:/Users/*******/Ruby_Programs/:

RE: How to tell Terminal which version of Ruby to use?

Hi

Quote (SBR210):

Someone said that I need to put the new version of Ruby's directory in the PATH prior to the old version's directory so that the system looks there first - is this correct?
That is what I would also recommend. Some other ways that come in mind
  • create a symlink called ruby, somewhere in a directory already enumerated somewhere in the front of the PATH, pointing to the new interpreter
  • create a Bash alias called ruby, having the value the full path to the new interpreter ( will no work in a shebang )
  • create a Bash function called ruby, executing one of the interpreters specified with full path based on PWD, choosing based on some rules you set up for it ( will not work in a shebang )
  • uninstall the old interpreter

Quote (SBR210):

If so, can anyone provide step by step instructions on how to do this?
I would suggest to ask that in a Mac OS forum. On thing to note anyway : the article you linked to talks about ~/.bash_login . That is executed only for login shells and shells started with --login option. But opening a terminal window in a graphic environment does not open a login shell, so the mentioned file will not be sourced. I suggest to move/copy the setting of PATH to the ~/.bashrc file.

Feherke.
http://free.rootshell.be/~feherke/

RE: How to tell Terminal which version of Ruby to use?

You can also look up "rvm" and install that...

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close