Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell Terminal which version of Ruby to use?

Status
Not open for further replies.

SBR210

Programmer
Sep 14, 2010
1
US
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 ( 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/:
 
Hi

SBR210 said:
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
[ul]
[li]create a symlink called ruby, somewhere in a directory already enumerated somewhere in the front of the [tt]PATH[/tt], pointing to the new interpreter [/li]
[li]create a Bash alias called ruby, having the value the full path to the new interpreter ( will no work in a shebang )[/li]
[li]create a Bash function called ruby, executing one of the interpreters specified with full path based on [tt]PWD[/tt], choosing based on some rules you set up for it ( will not work in a shebang )[/li]
[li]uninstall the old interpreter[/li]
[/ul]
SBR210 said:
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 [tt]PATH[/tt] to the ~/.bashrc file.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top