# Having three ruby versions installed

**URL:** <https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225>\
**Category:** Ruby\
**Created:** [November 25, 2006, 9:00am UTC](https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225 "2006-11-25T09:00:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 25, 2006, 9:00am UTC](https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225/1 "2006-11-25T09:00:31Z")

</div>

on my box running Mac OS X (Tiger the latest) i do have three ruby  
versions :

- /usr/bin/ruby # Apple’s default installed version :

# =\> 1.8.2

- /opt/local/bin/ruby # the MacPort version :

# =\> 1.8.5

- /Users/yvon/bin/jruby/jruby # svn installed

# =\> 1.8.5 (0) [java]

both MacPort and SVN versions cohabit nicely because using zsh (shell)  
aliases all commands of jruby have a “j” prefix and using a ~/.jgemrc  
i’m able to switch env vars between them.

then, the prob, reason for posting here, come with the default installed  
version.

here, when doing a :  
$ /usr/bin/ruby wav2xml.rb bidule.wav # i get :  
/usr/bin/ruby: No such file to load – ubygems (LoadError)

i think this is due to some env vars i setup :  
export RUBYOPT=rubygems  
export GEM\_HOME=/opt/local/lib/gems/1.8  
export RUBYLIB=/opt/local/lib/ruby/:/opt/local/lib/ruby/site\_ruby/1.8

because i’ve to design some scripts usable with apple’s default version,  
i’d like to find a workaround for that error message without installing  
anything within Apple’s ruby…

do you have a trick for that ?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 25, 2006, 9:20am UTC](https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225/2 "2006-11-25T09:20:33Z")

</div>

Une bÃ©vue wrote:

> both MacPort and SVN versions cohabit nicely because using zsh (shell)  
> i think this is due to some env vars i setup :  
> export RUBYOPT=rubygems  
> export GEM\_HOME=/opt/local/lib/gems/1.8  
> export RUBYLIB=/opt/local/lib/ruby/:/opt/local/lib/ruby/site\_ruby/1.8
> 
> because i’ve to design some scripts usable with apple’s default version,  
> i’d like to find a workaround for that error message without installing  
> anything within Apple’s ruby…
> 
> do you have a trick for that ?

Figure out what your search path is and symlink the desired Ruby version  
into the earliest (first searched) executable directory.

Example. Let’s say you have directory /usr/local/bin, and it is the  
first  
searched executable directory, and you want to execute  
/opt/local/bin/ruby  
instead of the Ruby version located at /usr/bin/ruby.

Move to directory /usr/local/bin, type this as root:

# ln -s /opt/local/bin/ruby ruby

Then test whether this worked. As a normal user:

$ ruby -version

But having multiple Ruby versions installed is a bad idea, because the  
different versions use libraries, some of them shared, that may cause  
conflicts.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 25, 2006, 11:16am UTC](https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225/3 "2006-11-25T11:16:43Z")

</div>

Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Figure out what your search path is and symlink the desired Ruby version  
> into the earliest (first searched) executable directory.

i don’t understand, if the desired version is the first hit in my search  
path then, no need for a symlink…

this is the case obviously i arranged the PATH such a way it hits first  
/opt/local/bin/ruby.

and then using the shebang “/usr/bin env ruby” i get the right one on my  
computer that’s to say the ones under /opt and a user of mine using the  
ones installed by Apple (being /usr/bin/ruby) with the same script and  
the same shebang said : “OK works fine !”

again normally i don’t care of the Apple default supplied Ruby BUT for  
testing purpose i might have to use it in order to verify my script  
under testing is able to work with the default ruby version on MacOS X  
(i’ve never done X-platform ruby).

And unfortunately, on my box, due to env vars the Apple’s one isn’t  
working with the shell i’m using (zsh).

When i’m testing a script under the Apple’s installed Ruby, generally  
it’s nearly the last step for me, the script is supposed to work under  
ruby 1.8.5 then i want only to verify it could work with 1.8.2 AND  
without any added extension to Ruby (otherwise i would have to embed in  
a bundle the ruby under /opt with the needed extensions).

To summarize the prob i want to solve is why, when i do :

$ /usr/bin/ruby \<a\_script\>

then using the default Apple’s ruby, i get an error message :

/usr/bin/ruby: No such file to load – ubygems (LoadError)

for a script which don’t use any gem and also with no one env var set to  
“ubygems” rather i do have effectively :

export RUBYOPT=rubygems

then the first “r” is mangled at leat…

in the mean time i’ve added an alias (\*) to my shell setup :

alias aruby=‘/usr/bin/ruby’ # Apple’s ruby

then doing :

$ aruby --version # gave me :  
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]

Right this is exactly wht i wanted except when i use it with a script :

$ aruby wav2xml.rb truc.wav # i get :

/usr/bin/ruby: No such dile to load – ubygems (LoadError)

which i don’t understand where it comes from…

- I think it’s better to use aliases rather than symlink because with  
that way i leave everything installed by Apple untouched.

> $ ruby -version
> 
> But having multiple Ruby versions installed is a bad idea, because the  
> different versions use libraries, some of them shared, that may cause  
> conflicts.

Quiet frankly i don’t think it is a bad idea having different version  
because the first one is the default installed ny Apple MacOS X and  
seems to be used by MacOS X then this one i want to leave it untouched.

the second one (which appears to be the first in my PATH) is absolutely  
independant of the first one, that’s the policy of MacPort the reason to  
install it under /opt, only MacPort use that directory, MacOS X doesn’t  
use it.

for the third being under my HOME, no prob at all it doesn’t interfere  
with the previous ones because all the command are prefixed by “j” for  
jRuby and it isn’t in my PATh at all, here i’m using zsh (shell) aliases  
rather :

alias jruby=“$JRUBY\_HOME/jruby”  
alias jgem=“$JRUBY\_HOME/jruby $JRUBY\_BIN/gem --config-file  
$HOME/.jgemrc”

etc…

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 25, 2006, 1:40pm UTC](https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225/4 "2006-11-25T13:40:58Z")

</div>

Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yes, “no prob at all” except all the problems you just listed. If the  
> situation had “no prob at all” you would not have posted, and your  
> error-free code would execute without error messages.

I desagree totally about what you said.

The prob, it is clear enough for me now, arroses from Apple’s faulty  
shell since 2 or 3 years. The “/usr/bin/env” doesn’t work correctly this  
has nothing to do with the three version i have.

I tell you, in case i have a RubyCocoa app to write and send it outside  
of my box, in that case i’ll have a fourth ruby version in a bundle,  
i’ve done that in the past and that works very-well when you must embed  
a ruby in an app.

Your solution would be to leave only on my box the Apple’s version of  
Ruby, used by MacOS X, afaik, then I can’t use it because i can’t  
install rubygems with this version ; this is good practice to let the OS  
version as it is.

Then logically i need at least a second version to install any gems i  
need, also C ext to ruby i’m writing.

And because i want to use some java libs i need the third one jRuby.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 25, 2006, 12:40pm UTC](https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225/5 "2006-11-25T12:40:53Z")

</div>

Une bÃ©vue wrote:

> Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Figure out what your search path is and symlink the desired Ruby version  
> > into the earliest (first searched) executable directory.
> 
> i don’t understand, if the desired version is the first hit in my search  
> path then, no need for a symlink…

The point is to know which version you are executing. If you only want  
to  
execute one version of Ruby, then remove the other two from your system.  
Otherwise you will have times when you are not sure which version gets  
executed. A symlink can simplify this problem, and it can do so without  
some of the problems you are having with environmental variables.

> this is the case obviously i arranged the PATH such a way it hits first  
> /opt/local/bin/ruby.

What? You are editing your search path? This is another bad idea. When  
you  
edit your search path and launch a new shell, previously launched shells  
will use the old search path and new shells will use the new search  
path.  
Also, different shells may treat the path differently, depending on how  
(or  
if) they get the new path information. This can be very, very confusing.

Conclusion? Don’t edit your search path. Change Ruby versions some other  
way. Like with symlinks.

> and then using the shebang “/usr/bin env ruby” i get the right one on my  
> computer that’s to say the ones under /opt and a user of mine using the  
> ones installed by Apple (being /usr/bin/ruby) with the same script and  
> the same shebang said : “OK works fine !”

All fine, except these problems you are having.

> again normally i don’t care of the Apple default supplied Ruby BUT for  
> testing purpose i might have to use it in order to verify my script  
> under testing is able to work with the default ruby version on MacOS X  
> (i’ve never done X-platform ruby).
> 
> And unfortunately, on my box, due to env vars the Apple’s one isn’t  
> working with the shell i’m using (zsh).

Don’t use environmental variables to try to force use of a particular  
version of Ruby. Some applications will not read the variables the way  
you  
expect. And the problem with existing shells, new shells and your path  
applies to environmental variables as well.

> then using the default Apple’s ruby, i get an error message :
> 
> /usr/bin/ruby: No such file to load – ubygems (LoadError)
> 
> for a script which don’t use any gem and also with no one env var set to  
> “ubygems” rather i do have effectively :
> 
> export RUBYOPT=rubygems
> 
> then the first “r” is mangled at leat…

Another reason not to rely on environmental variables.

> in the mean time i’ve added an alias (\*) to my shell setup :
> 
> alias aruby=‘/usr/bin/ruby’ # Apple’s ruby

Aliases? Why, oh why, are you making this so complicated?

If you use an alias, or if your change your path, or if you rely on  
environmental variables, each of these will lead to confusion and  
errors,  
because different shells treat these quantities differently, and new  
shells  
will have different values than old shells.

Also, if you use the “system()” call or use backticks in your Ruby  
program,  
which shell will you be using? Do you know? Which environmental values,  
which aliases, which path will be in force for that shell?

For all these reasons, IMHO you should stop using these methods.

> /usr/bin/ruby: No such dile to load – ubygems (LoadError)
> 
> which i don’t understand where it comes from…

You may not know, but I think I know. Your entire setup is way too  
complicated.

> - I think it’s better to use aliases rather than symlink because with  
> that way i leave everything installed by Apple untouched.

Except:

1. You can’t make a particular version of Ruby run.

2. Perfectly good Ruby code raises bogus error messages.

I would think this would make you wonder whether your setup is working  
as it  
should.

> > Then test whether this worked. As a normal user:
> > 
> > $ ruby -version
> > 
> > But having multiple Ruby versions installed is a bad idea, because the  
> > different versions use libraries, some of them shared, that may cause  
> > conflicts.
> 
> Quiet frankly i don’t think it is a bad idea having different version  
> because the first one is the default installed ny Apple MacOS X and  
> seems to be used by MacOS X then this one i want to leave it untouched.

All fine, except that you cannot make your present setup work.

> alias jruby=“$JRUBY\_HOME/jruby”  
> alias jgem=“$JRUBY\_HOME/jruby $JRUBY\_BIN/gem --config-file  
> $HOME/.jgemrc”
> 
> etc…

Yes, “no prob at all” except all the problems you just listed. If the  
situation had “no prob at all” you would not have posted, and your  
error-free code would execute without error messages.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 25, 2006, 7:05pm UTC](https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225/6 "2006-11-25T19:05:28Z")

</div>

Une bÃ©vue wrote:

> Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Yes, “no prob at all” except all the problems you just listed. If the  
> > situation had “no prob at all” you would not have posted, and your  
> > error-free code would execute without error messages.
> 
> I desagree totally about what you said.

You can’t disagree that your system isn’t working as it should. If that  
were  
true, you wouldn’t have posted.

> The prob, it is clear enough for me now, arroses from Apple’s faulty  
> shell since 2 or 3 years. The “/usr/bin/env” doesn’t work correctly this  
> has nothing to do with the three version i have.

Yes, I understand that. So instead of using:

/usr/bin/env ruby -w

You can instead use:

/usr/local/bin/ruby -w

On ALL your Ruby scripts, no matter how numerous they become, and then,  
when  
you want to change Ruby versions, just change the destination for the  
symlink located at /usr/local/bin/ruby.

That way, no matter how many scripts you have, even if they call each  
other,  
and even if they use “system()” and backticks, they will all use the  
same  
Ruby version, until you change the symlink again.

> I tell you, in case i have a RubyCocoa app to write and send it outside  
> of my box, in that case i’ll have a fourth ruby version in a bundle,  
> i’ve done that in the past and that works very-well when you must embed  
> a ruby in an app.

Use a symlink to sort this out, to make all your scripts cooperate on  
the  
version of Ruby to use at a particular moment.

> Your solution would be to leave only on my box

I offered that as an alternative, not a solution. It was meant to show  
the  
advantage of the symlink.

> the Apple’s version of  
> Ruby, used by MacOS X, afaik, then I can’t use it because i can’t  
> install rubygems with this version ; this is good practice to let the OS  
> version as it is.

The solution I offered was to create a symlink located  
at /usr/local/bin/ruby, and not edit your path, and not use  
environmental  
variables and not use aliases. This will allow you to use more than one  
Ruby version, IF they don’t write to each other’s library locations.

> Then logically i need at least a second version to install any gems i  
> need, also C ext to ruby i’m writing.

No problem … as long as you use a symlink to get all your scripts to  
agree  
on which Ruby to use, and as long as the library issue doesn’t come up.

> And because i want to use some java libs i need the third one jRuby.

Already addressed. Another advantage to the symlink approach is that, if  
you  
try:

$ ruby -version

The result will be consistent, so Ruby version tests will also work as  
they  
should, and you can get all your scripts to change Ruby versions  
instantly,  
including those that might be launched from a pre-existing shell.

BTW what happened to the good code that produced an error message? What  
was  
the outcome on that?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 25, 2006, 9:27pm UTC](https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225/7 "2006-11-25T21:27:43Z")

</div>

Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > And because i want to use some java libs i need the third one jRuby.
> 
> Already addressed. Another advantage to the symlink approach is that, if you  
> try:
> 
> $ ruby -version
> 
> The result will be consistent

ok for jruby itself i could do also a symlink.

but jruby by itself is useless

for example i want to install a gem into the ruby under jruby

the expended command line would be :

/Users/yvon/bin/jruby/bin/jruby /users/yvon/bin/jruby/bin/gem  
–config-file /users/yvon/.jgemrc install

with my alias i can do simply :

jgem install

again, in my opinion, it is much more simpler to use (zsh) aliases than  
symlinks because those aliases ar writen in a standard text file.

to terminate with (i don’t want to convince you) from time to time, i  
write ruby extension in C, the way i call the compiler is simply :

ycc file.c

because in the aliases file of zsh o do have a line like that :

alias ycc='cc -W -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes  
-pedantic -stb=c99 -O2 -pipe -o ’

i could do a symlink to a shell script called “ycc” and doing the above  
line, i agree also, but quiet frankly it’s so easy to add an alias into  
the "aliases file of zsh…

i do have a lot like that, last example, some times from Terminal we  
have to cd tp the ~/Desktop i do have an alias for that :

alias -g ‘yd’=‘~/Desktop’

in the terminal i’ve only to enter :

cd yd

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 25, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/having-three-ruby-versions-installed/77225/8 "2006-11-25T21:25:42Z")

</div>

Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I desagree totally about what you said.
> 
> You can’t disagree that your system isn’t working as it should. If that were  
> true, you wouldn’t have posted.

the prob doesn’t come from the shebang, it is specific to ONE script, i  
don’t know why, for the time being, but i did, in the mean time a test  
“shebang.rb” and it works great as expected either by using :

./shebang.rb one two three four

(the script needs args)

or :

/opt/local/bin/ruby shebang.rb five six seven

i suspected a wrong char but my text editor (able to view invisible  
chars) doesn’t present anything wrong…

i’ve put all of this stuff here :

[http://thoraval.yvon.free.fr/Audio](http://thoraval.yvon.free.fr/Audio)

i did a ktrace over the faulty script “wav2xml.rb” but i’m not skilled  
enough to interpret it.

> > The prob, it is clear enough for me now, arroses from Apple’s faulty  
> > shell since 2 or 3 years. The “/usr/bin/env” doesn’t work correctly this  
> > has nothing to do with the three version i have.

i’ve posted that point onto a french mailing list and the list  
maintainer (much more skilled than me, afaik) said it doesn’t agree with  
that it is him having advice doing a “shebang.rb” test and also  
afterwards a ktrace.

OK, i got the “solution” right now

it is MY writing faulty effectively in the shebang instead of writing :

#!/usr/bin/env ruby -w

i DO HAVE writen :

#/usr/bin/env ruby -w

that’s to say i’ve forgotten the “bang” of shebang “!”…

right now the script is OK in any case…

> you want to change Ruby versions, just change the destination for the  
> symlink located at /usr/local/bin/ruby.

OK i agree that’s a solution but with this solution the script won’t  
work on another computer where the default ruby is in /usr/bin/ruby…
