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 :(

Gravatar icon
Anko Painting
Thursday January 01, 2009 @ 04:35 PM (PST)

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.

Gravatar icon
Thursday January 01, 2009 @ 04:42 PM (PST)

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

Gravatar icon
Thursday January 01, 2009 @ 04:54 PM (PST)

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.

Gravatar icon
Thursday January 01, 2009 @ 05:10 PM (PST)

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.

Gravatar icon
JB Smith
Wednesday January 07, 2009 @ 08:36 AM (PST)

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

Gravatar icon
Wednesday January 07, 2009 @ 09:41 AM (PST)

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/

Gravatar icon
Friday January 16, 2009 @ 06:02 PM (PST)

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.

Gravatar icon
Sunday February 01, 2009 @ 10:23 AM (PST)

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

Gravatar icon
Sunday February 01, 2009 @ 10:31 AM (PST)
Gravatar icon
Sunday February 01, 2009 @ 10:34 AM (PST)

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.

Gravatar icon
Sunday February 01, 2009 @ 11:57 AM (PST)

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.

Gravatar icon
Alexander Ivanov
Tuesday February 10, 2009 @ 04:33 AM (PST)

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.

Gravatar icon
Logy Laps
Friday March 20, 2009 @ 11:32 PM (PDT)

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.

Gravatar icon
gw
Thursday April 30, 2009 @ 09:19 PM (PDT)

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!

Gravatar icon
Saturday July 04, 2009 @ 10:46 PM (PDT)

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.

Gravatar icon
Sunday July 05, 2009 @ 12:13 PM (PDT)

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.

Gravatar icon
Tuesday August 25, 2009 @ 03:54 AM (PDT)

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

Gravatar icon
Dodo
Wednesday September 02, 2009 @ 02:23 PM (PDT)

$ 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

Gravatar icon
erwin
Thursday September 10, 2009 @ 10:06 AM (PDT)

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!

Gravatar icon
Dida
Sunday September 20, 2009 @ 09:43 AM (PDT)

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.

Gravatar icon
Tuesday September 29, 2009 @ 05:22 PM (PDT)

include in your configure line —enable-static

Gravatar icon
Dominic Son
Saturday November 07, 2009 @ 10:26 PM (PST)

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.

Gravatar icon
Stephen Myles Prather
Wednesday November 11, 2009 @ 06:51 PM (PST)

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?

Gravatar icon
Billy
Wednesday January 27, 2010 @ 02:39 AM (PST)

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

Gravatar icon
David
Thursday January 28, 2010 @ 12:27 AM (PST)

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.

Gravatar icon
Saturday January 30, 2010 @ 11:59 AM (PST)

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.

Gravatar icon
Saturday January 30, 2010 @ 12:08 PM (PST)

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.

Gravatar icon
Saturday January 30, 2010 @ 01:03 PM (PST)
New comment

required, won't be displayed

optional

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile.

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