How to tell Terminal which version of Ruby to use?

S

Sam Riffe

Hello,

I have two entry level 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?

[Side Note: I actually somehow got it to work when I first installed
1.9.2, but I have networked computers and a wireless Apple Time Machine
backing up both machines that is somehow communicating shell settings
via the backup mechanism, from my un-upgraded MacBook back to the iMac
that has the new 1.9.2 installed. Somehow the PATH settings from the
MacBook seems to be overriding what's on the iMac. I've noticed the
same thing happens with my TextMate preferences - the style preferences
on the laptop get transferred to the one on the iMac in realtime
somehow. After I figure out how to fix this, I'm going to change the
shell settings on both machines to try and prevent this. Just curious
if others have encountered this issue.]

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/ad...thin-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)". The file definitely exists
and is a functional Ruby program. I did change the name of the
directory to "Ruby Programs" and then back to "Ruby_Programs" - could
that have somehow caused this problem?

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

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


3. I can't get the shebang line to work in any of my Ruby programs. Is
there a specific permission that needs to be set on Mac files to get the
shebang line to work? It points to the right directory that contains
the Ruby interpreter and it's supposed to be a fairly simple line of
code, but I'm never able to run Ruby programs in the shell without the
"ruby" preface in the command line.

Thanks in advance.
 
M

Markus Schirp

I suffered from similar problems in the past. Now I'm a big fan of the
tool rvm. It helps you to install and switch between your rubies.

Im unsure weather it works on mac, but you can give it a try:

http://rvm.beginrescueend.com



Hello,

I have two entry level 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?

[Side Note: I actually somehow got it to work when I first installed
1.9.2, but I have networked computers and a wireless Apple Time Machine
backing up both machines that is somehow communicating shell settings
via the backup mechanism, from my un-upgraded MacBook back to the iMac
that has the new 1.9.2 installed. Somehow the PATH settings from the
MacBook seems to be overriding what's on the iMac. I've noticed the
same thing happens with my TextMate preferences - the style preferences
on the laptop get transferred to the one on the iMac in realtime
somehow. After I figure out how to fix this, I'm going to change the
shell settings on both machines to try and prevent this. Just curious
if others have encountered this issue.]

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/ad...thin-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)". The file definitely exists
and is a functional Ruby program. I did change the name of the
directory to "Ruby Programs" and then back to "Ruby_Programs" - could
that have somehow caused this problem?

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

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


3. I can't get the shebang line to work in any of my Ruby programs. Is
there a specific permission that needs to be set on Mac files to get the
shebang line to work? It points to the right directory that contains
the Ruby interpreter and it's supposed to be a fairly simple line of
code, but I'm never able to run Ruby programs in the shell without the
"ruby" preface in the command line.

Thanks in advance.
 
D

Diego Virasoro

Hi,
bash will look for files in the PATH but in the same order as in PATH.
Hence if you have two files/programs called the same in two different
directories included in the PATH, bash will give you the first one.

That may explain some of the problems.

The shebang only works if your file is set as an executable. To fix
that you can use:
chmod 755 <filename>

Finally I don't think you need to have the final colon in your PATH...
though I don't know if that has any effect.

How that helps
Diego

Hello,

I have two entry level 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?

[Side Note: I actually somehow got it to work when I first installed
1.9.2, but I have networked computers and a wireless Apple Time Machine
backing up both machines that is somehow communicating shell settings
via the backup mechanism, from my un-upgraded MacBook back to the iMac
that has the new 1.9.2 installed.  Somehow the PATH settings from the
MacBook seems to be overriding what's on the iMac.  I've noticed the
same thing happens with my TextMate preferences - the style preferences
on the laptop get transferred to the one on the iMac in realtime
somehow.  After I figure out how to fix this, I'm going to change the
shell settings on both machines to try and prevent this.  Just curious
if others have encountered this issue.]

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/ad...thin-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)".  The file definitely exists
and is a functional Ruby program.  I did change the name of the
directory to "Ruby Programs" and then back to "Ruby_Programs" - could
that have somehow caused this problem?

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

$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/sbrriffe/src:/usr/X11/b in:/Users/sbriffe/Ruby_Programs/:

3. I can't get the shebang line to work in any of my Ruby programs.  Is
there a specific permission that needs to be set on Mac files to get the
shebang line to work?  It points to the right directory that contains
the Ruby interpreter and it's supposed to be a fairly simple line of
code, but I'm never able to run Ruby programs in the shell without the
"ruby" preface in the command line.

Thanks in advance.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top