[Mac OS X] having three ruby versions installed

U

Une bévue

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 ?
 
U

Une bévue

Paul Lutus said:
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.
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.

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...
 
U

Une bévue

Paul Lutus said:
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.
 
U

Une bévue

Paul Lutus 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>

i did a ktrace over the faulty script "wav2xml.rb" but i'm not skilled
enough to interpret it.
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...
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.

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...
 
U

Une bévue

Paul Lutus said:
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 <some gem>

with my alias i can do simply :

jgem install <some gem>

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
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top