Now that Ruby 1.9.1 is out, a lot of Ruby developers are going to want to run it alongside a 1.8.x build to test their apps. Here’s how to compile and install Ruby 1.9.1 alongside an existing Ruby installation on Mac OS X Leopard without disturbing that installation or any gems.

Note: You’ll need to have Xcode installed, since it provides the development tools necessary for the compilation step. If you don’t already have Xcode, you can install it from your Mac OS X installation DVD or download it from Apple for free.

First, download and extract the release:

curl ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.9.1-p0.tar.bz2 -o ruby-1.9.1-p0.tar.bz2
tar xjf ruby-1.9.1-p0.tar.bz2

Next, compile Ruby, specifying a suffix for the binaries. This will create binaries named ruby19, irb19, gem19, etc., which will coexist peacefully with the stable ruby, irb, and gem binaries:

cd ruby-1.9.1-p0/
autoconf
./configure --program-suffix=19 --enable-shared --with-readline-dir=/usr/local
make && sudo make install

That’s all there is to it.

Update: Updated to resolve potential readline-related errors.

Update 2: The stable release of 1.9.1 is now out, so I’ve updated the instructions accordingly.

Comments

Any luck getting hpricot installed with this configuration? It won’t compile for me, which means i can’t get sanitize :(

No luck yet. Hpricot doesn’t want to compile against 1.9.1, and the Hpricot website and bug tracker have been down for days. I’m as frustrated as you are.

I get persistent errors during the final “make && sudo make install” command. Any thoughts? Here’s the log:

compiling readline
gcc -I. -I../../.ext/include/i386-darwin9.6.0 -I../.././include -I../.././ext/readline -DRUBY_EXTCONF_H=\“extconf.h\” -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -O2 -g -Wall -Wno-parentheses -pipe -fno-common -o readline.o -c readline.c
readline.c: In function ‘filename_completion_proc_call’:
readline.c:1130: warning: implicit declaration of function ‘completion_matches’
readline.c:1131: error: ‘filename_completion_function’ undeclared (first use in this function)
readline.c:1131: error: (Each undeclared identifier is reported only once
readline.c:1131: error: for each function it appears in.)
readline.c:1131: warning: assignment makes pointer from integer without a cast
readline.c: In function ‘username_completion_proc_call’:
readline.c:1156: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:1156: warning: assignment makes pointer from integer without a cast
make1: * [readline.o] Error 1
make: *
[exts] Error 1

Try replacing the ./configure command with this:

./configure --prefix=/usr/local --program-suffix=19 --with-readline-dir=/usr/local

Does that work? If so, I’ll update the post.

I found that when I compiled, I had the same issues as Jim Gagne.
By using

./configure—prefix=/usr/local —program-suffix=1.9 —enable-shared —without-readline
make clean
make

I could get it to compile but clearly readline should not work.
Going back and doing

./configure —prefix=/usr/local —program-suffix=1.9 —enable-shared —with-readline-dir=/usr/local
make clean
make

now will compile properly.

I had tried this second option many times, but it never worked before I did a run without the readline option.

Strange that it would somehow begin working afterward.

Thanks JB. I’ve updated the post to refer to your comment for a solution to the readline problem.

I had the same issue. This is what worked for me. Also the link below the command may also be helpful I followed the readline steps in the blog before the line below was applied.

./configure —program-suffix=19 —with-readline-dir=/usr/local

http://blog.bogojoker.com/2008/06/installing-ruby-187-on-mac-os-x-1053/

there seems to be a way getting hpricot running with ruby 1.9.1, see also this posting: http://frozenplague.net/2009/01/ruby-191-rubygems-rails/

since hpricot is planned to be included in the upcoming rubyosx distribution, so any comments or progress updates via email to our list ( http://rubyforge.org/mailman/listinfo/rubyosx-list ) are highly appreciated.

we are working on updated packages for the rubyosx project.
after making a fresh compile of ruby 1.9.1-p0 on osx 10.5.6 i have the folowing output when running “ruby runner.rb” in the /test directory
5779 tests, 2514699 assertions, 29 failures, 1 errors, 0 skips
see the detailed output here:
http://rubyforge.org/pipermail/rubyosx-list/2009-February/000010.html

maybe you guys can post your test output to the rubyosx list, so we can see what tests fail on your system? thanks! parasew

I’ve patched Hpricot to get it running on Ruby 1.9.1 and sent a pull request to why. The development version of Hpricot on GitHub doesn’t pass its own tests, but it doesn’t do any worse after my patch. YMMV.

I’ve installed Ruby 1.9.1 following your instructions (no problems),then installed gem (no problems) and had got two Ruby (1.8.7 & 1.9.1) / gem pairs at the same time on my machine.

Using gem19 installed rails. But when I tried to run rails has got

alexander-ivanovs-macbook-pro:t AVI$ rails —version
:249:in `push_gem_version_on_load_path’: undefined method `<=>’ for nil:NilClass (NoMethodError)
from :14:in `gem’
from /usr/local/bin/rails:18:in `’

To get working rails back it was required to sudo gem install rails again.

How to
- install rails for 1.9.1
- run it on 1.9.1 (at least I would like to try that for new apps) with all rake, script/… atc.

I am not sure how to keep both versions of ruby (1.8.7 & 1.9.1) since i just replaced it completely, but I had the same ‘push_gem_version_on_load_path’ error when running ‘rails’. The solution was simply to run ‘sudo gem install rails’… all is well now.

So… n00b question. I compiled using the above. Seems to work. A few quick irb19 experiments work ok. Next, I want to collect the compiled results to copy to other machines (same OS/CPU combo).

I see a number of xyz19 apps in /usr/local/bin, but what else is there that has to be copied to other machines, and where would I find this list of what actually got installed and where?

Is it worth going that route, or am I better off going through the compile process on each machine?

THx.

How do you keep the binaries created by gem19 separate?

For example: gem19 install ZenTest installs the binary autotest. but if you use that same binary for 1.8.7 then you have trouble.

Ciao!

Use the --format-executable option when installing the gem and RubyGems will name the gem executable to match your Ruby executable. So gem19 install ZenTest --format-executable should give you an executable named autotest19.

Hi,

Please update the download path or even better just put a link to ruby download page and change the following instruction to:

tar xvf ruby-1.9.1-p243.tar.gz (please note: the name of the tar would most probably change so please use the correct one)

Rest of the instructions remain the same. Awesome tutorial.

@Ryan: thanks for pointing out a way to install gems exclusively for ruby1.9.

I installed ruby following your tutorial and it worked. But, I noticed too late that it did not update my ruby 1.8.6 but install it too. What can I do to remove this -19 ending and replace ruby 1.8.6? Thanks for help,

Dodo

$ ruby19 —version
ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin10.0.0]

I just replaced the readline5.2 by last version of readline 6.0
ftp://ftp.cwru.edu/pub/bash/readline-6.0.tar.gz

this get rid of : username_completion_proc_call error

Erwin,

I did compile readline 6.0 using a standard configure & make & make install. But i still have the same “username_completion_proc_call” error. How do you compile readline? Mine was end up like this:

/bin/sh ../support/shlib-install -O darwin10.0.0 -d /usr/local/lib -b /usr/local/bin -i “/usr/bin/install -c -m 644” libreadline.6.0.dylib
install: you may need to run ldconfig

So, how do you compile readline? I’m using Snow Leopard as well.

Thanks!

THIS WORKED FOR ME!

./configure —prefix=/usr/local —enable-pthread —enable-shared —with-readline-dir=/usr/local

(be sure convert options back to double-dashes)
THANK GOD! I’m no longer in compiler hell!

Go internet.

include in your configure line —enable-static

myles ruby-1.9.1-p243 % pwd
/home/myles/Desktop/ruby-1.9.1-p243
myles ruby-1.9.1-p243 % grep readline configure
Exit 1

Why does it seem like I’m the only person having this problem? No Google hits. I had to cd ext/readline; ruby extconf.rb; make; sudo make install.

I have the same problem and the exact same error as Dida had with configuring, making, and installing Readline 6.0. I tried doing ./configure —enable-static, but the make still doesn’t work.

The above solution also fails for ruby-1.9.1-p376, and I get the “username_completion_proc_call error” still. Is this still not working? Or am I doing something wrong?

Macintosh-10:ruby Daneshforooz$ ./configure —program-suffix=19 —enable-shared —with-readline-dir=/usr/local
configure: WARNING: unrecognized options: —with-readline-dir
checking build system type… i386-apple-darwin10.2.0
checking host system type… i386-apple-darwin10.2.0
checking target system type… i386-apple-darwin10.2.0
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: in `/Users/Daneshforooz/ruby’:
configure: error: no acceptable C compiler found in $PATH
See `config.log’ for more details.

What I am I doing wrong?

PLEASE HELP

I’m not seeing it either. Would prefer to use libedit explicitly anyway, since readline is not free… but I don’t see any such options in the generated configure script.

Actually, I just noticed that the autoconf that executes first in $PATH is in /opt/local/bin, which is created by Macports. Running the Apple version (/Developer/usr/bin/autoconf) solved the problem.

By solved, I mean that the Apple autoconf just accepts any weird arguments without complaining, like —with-monkey-in-your-hair-dir=/usr/local.

The build seems ok though.

Got the same problem with Oisin, but cant fix it via any newly installed or built-in version of autoconf.

Thanks, works great for me. However, for dummies, it’d be nice to mention run with 19 at the end
ex.
ruby19
gems19

I know, its obvious but it took me a minute :D.
I must also note that it took a few mintutes to compile. (on a macbook1,1. I know, but eh its a mac :P)

Copyright © 2002-2012 Ryan Grove. All rights reserved.
Powered by Thoth.