Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Install Ruby 1.9 alongside Ruby 1.8 UNIX
I have put together a process that will make Ruby 1.9 from source, and install the resulting binaries in the folder of your choice. The script downloads all the files and patches to /tmp. I also wrote a script that allows me to swap ruby 1.8 and 1.9 as I need.

Here's how I installed the newer version of Ruby in its own directory. First, I downloaded, compiled, and installed readline and patch:
$ cd /tmp
$ curl -O ftp://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz
$ tar xzvf readline-5.2.tar.gz
$ cd readline-5.2
$ curl -O http://ftp.gnu.org/gnu/readline/readline-5.2-patches/readline52-012
$ patch -p0 <>
$ ./configure --prefix=$HOME/
$ make
$ sudo make install
$ cd ..
Next, I downloaded, compiled, and installed the latest version of Ruby, picking up right where the above commands left off (comments denoted with #):
$ rm index.ht*
$ wget -F ftp://ftp.ruby-lang.org/pub/ruby/1.9/
# I am only interesting in the tar.gz files
# you can go crazy and do a less/more cryptic regex here.
$ sed -e 's#<[^>]*>##g' index.html |sed -e 's#.*File *##g'|sed -e '1,6d'|sed 'N;$!P;$!D;$d'| sed -e '/zip/d'|sed -e '/bz2/d'
$ echo -n "please enter a file from the above list:"
$ read -e Ruby_File
$ curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.9/$Ruby_File
$ tar xzvf {$Ruby_File}
# since we are working in /tmp, I assumed there are no
# existing directories with namme ruby.....
$ cd ruby*
$ autoconf
$ sudo ./configure --prefix=$HOME/ruby--with-readline-dir=$HOME/
$ sudo make
$ sudo make install
Now I have safely installed Ruby 1.9 in a place where it does not disturb the original Ruby. You can change where to install Ruby by replacing $HOME above with whatever directory you want to use.

The following script allows me to swap default Ruby versions. Instead of changing the path, I rebuild the links every time. I should mention that rake in my system is in /usr/bin, and I had to adjust my script to take care of that.
#!/usr/bin/env bash
rbv=$(ruby -v)
rv=${rbv:5:3}

function r18 () {
  ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/erb /usr/bin/erb
  ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem /usr/bin/gem
  ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/irb /usr/bin/irb
  ln -s /usr/bin/rake.1.8 /usr/bin/rake
  ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/rdoc /usr/bin/rdoc
  ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ri /usr/bin/ri
  ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby /usr/bin/ruby
  ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/testrb /usr/bin/testrb
}

function r19 () {
  ln -s /Users/luis/ruby1.9/bin/erb /usr/bin/erb
  ln -s /Users/luis/ruby1.9/bin/gem /usr/bin/gem
  ln -s /Users/luis/ruby1.9/bin/irb /usr/bin/irb
  ln -s /Users/luis/ruby1.9/bin/rake /usr/bin/rake
  ln -s /Users/luis/ruby1.9/bin/rdoc /usr/bin/rdoc
  ln -s /Users/luis/ruby1.9/bin/ri /usr/bin/ri
  ln -s /Users/luis/ruby1.9/bin/ruby /usr/bin/ruby
  ln -s /Users/luis/ruby1.9/bin/testrb /usr/bin/testrb
}

function cleanruby () {
  rm /usr/bin/erb
  rm /usr/bin/gem
  rm /usr/bin/irb
  rm /usr/bin/rake
  rm /usr/bin/rdoc
  rm /usr/bin/ri
  rm /usr/bin/ruby
  rm /usr/bin/testrb
}

if [ ${rv} = 1.8 ]; then
  echo "Current version is 1.8 swaping to 1.9"
  cleanruby
  r19
elif [ ${rv} = 1.9 ]; then
  echo "Current version is 1.9 swapping to 1.8"
  cleanruby
  r18
fi
exit
[robg adds: Note that this code originally appeared in this entry on the author's blog. I have reformatted and reworded it slightly for use here. Any mistakes are my responsibility; if you have any problems, check the blog post for the original code. An alternative method of getting the newest Ruby installed in its own directory would be to install MacPorts and get it from there.]
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (11 votes cast)
 
[12,414 views]  

Install Ruby 1.9 alongside Ruby 1.8 | 8 comments | Create New Account
Click here to return to the 'Install Ruby 1.9 alongside Ruby 1.8' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Install Ruby 1.9 alongside Ruby 1.8
Authored by: chrismear on Aug 04, '09 08:22:25AM
If you're installing multiple Rubys for testing purposes, the ZenTest gem has a tool called multiruby which will download, compile and install several versions automatically, and let you run test suites or any other script against all the versions:

http://blog.zenspider.com/2007/12/testing-for-ruby-18-and-19-usi.html

[ Reply to This | # ]
Install Ruby 1.9 alongside Ruby 1.8
Authored by: sjk on Aug 04, '09 12:33:02PM
An alternative method of getting the newest Ruby installed in its own directory would be to install MacPorts and get it from there.
Yup:
% port info ruby19
ruby19 @1.9.1-p129 (lang, ruby)
Variants:    c_api_docs, mactk, nosuffix, tk, universal



[ Reply to This | # ]
Install Ruby 1.9 alongside Ruby 1.8
Authored by: BushyMark on Aug 07, '09 11:20:14PM

Does anyone else get this error after this step? Just wondering if it was something to worry about

→ patch -p0 <>
-bash: syntax error near unexpected token `newline'

Thanks for the help!



[ Reply to This | # ]
Install Ruby 1.9 alongside Ruby 1.8
Authored by: enderai on Aug 14, '09 11:13:15AM
Swapping symlinks in /usr/bin is a really bad idea, as this has a system-wide effect rather than just changing things for your user, and you need to sudo every time. A better way to get the same effect is to prepend your PATH with the bin dir where ruby 1.9 is installed:

% export PATH=$HOME/ruby1.9/bin:$PATH
% which ruby
/Users/enderai/ruby1.9/bin/ruby


[ Reply to This | # ]
Install Ruby 1.9 alongside Ruby 1.8
Authored by: lmcdougall on Aug 22, '09 10:32:03AM

Changing the links is not such an awful idea as it may sound. By doing so, you are making sure that there is no other variables affecting your development environment. In fact a similar procedure is used by Gentoo-linux and it variants. ("eselect ruby [list|set] ..").



[ Reply to This | # ]
Install Ruby 1.9 alongside Ruby 1.8
Authored by: lmcdougall on Aug 22, '09 10:37:45AM

The line:
$ patch -p0 <>
should read:
patch -p0 <readline52-012



[ Reply to This | # ]
Install Ruby 1.9 alongside Ruby 1.8
Authored by: rfzabick on Oct 16, '09 10:40:14AM

I tried the macport approach. Now I have ruby binaries with a 1.9 suffix in my /opt/local/bin. But my old 1.8 binaries are already in that directory without suffixes. Should I rename the 1.8 binaries with a suffix and then remove the suffix from the 1.9 binaries?

How does this install affect my gems? What if I rename the binaries as described above? How will that affect my gems?

I've spent a fair amount of time googling this, but I can't find anywhere that describes how to handle the admin side of ruby and its upgrades.



[ Reply to This | # ]
Install Ruby 1.9 alongside Ruby 1.8
Authored by: agitatedString on Oct 30, '11 02:19:20AM

Ruby Version Manager (RVM) at http://beginrescueend.com/



[ Reply to This | # ]