Building ruby on Mac OS X Leopard

Yesterday was released a new update for ruby in order to solve some vulnerabilities. As ruby is included on Leopard I'm going to explain how to built ruby from source.

This tutorial is divided in three parts: Readline, Ruby and Ruby readline extension. Readline and ruby can be build both at the same time then you can open two terminals and copy and paste the following.

Building Readline

*Getting sources and unpacking


READLINE TERMINAL
iMac:Downloads ricard$ wget http://www.forniol.cat/manuals/readline52-package-sources.tar.bz2
iMac:Downloads ricard$ tar jxf readline52-package-sources.tar.bz2

NOTE: There should be two folders readline-5.2 and readline-5.2-patches

*Patching Readline: 12 patches


READLINE TERMINAL
iMac:Downloads ricard$ cd readline-5.2
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-001
  patching file display.c
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-002
  patching file display.c
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-003
  patching file display.c
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-004
  patching file display.c
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-005
  patching file complete.c
  patching file input.c
  patching file isearch.c
  patching file misc.c
  patching file readline.c
  patching file text.c
  patching file vi_mode.c
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-006
  patching file display.c
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-007
  patching file display.c
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-008
  patching file display.c
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-009
  patching file display.c 
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-010
  patching file display.c
  Hunk #1 succeeded at 1623 (offset 4 lines).
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-011
  patching file input.c
iMac:readline-5.2 ricard$ patch -p0 < ../readline-5.2-patches/readline52-012
  patching file support/shobj-conf

*Configuring and building


READLINE TERMINAL
iMac:readline-5.2 ricard$ mkdir build
iMac:readline-5.2 ricard$ cd build
iMac:build ricard$ ../configure −−prefix=/opt/ruby && make

Building Ruby

While readline is being configured and compiled, open a new terminal.

*Getting sources and unpacking


RUBY TERMINAL
iMac:Downloads ricard$ wget http://www.forniol.cat/manuals/ruby-1.8.6-p230-and-osx_patch.tar.bz2
iMac:Downloads ricard$ tar jxf ruby-1.8.6-p230-and-osx_patch.tar.bz2

NOTE: There should be a folder named ruby-1.8.6-p230 and a file named ruby-osx.diff

*Patching Ruby to build on Leopard

 

RUBY TERMINAL
iMac:Downloads ricard$ cd ruby-1.8.6-p230
iMac:ruby-1.8.6-p230 ricard$ patch -p0 < ../ruby-osx.diff

*Configuring, Building


RUBY TERMINAL
iMac:ruby-1.8.6-p230 ricard$ mkdir build
iMac:ruby-1.8.6-p230 ricard$ cd build
iMac:build ricard$ ../configure −−prefix=/opt/ruby −−enable-frame-address \
                                −−enable-largefile   −−enable-pthread \
                                −−enable-shared   −−enable-install-doc \
                                −−without-readline && make

Installing Readline and Ruby


READLINE TERMINAL
iMac:build ricard$ sudo make install


RUBY TERMINAL
iMac:build ricard$ sudo make install 

Building Ruby Readline extension apart

When readline installation has finished then go back to ruby source folder. Ruby install is a bit long but it's because generates documentation.


READLINE TERMINAL
iMac:build ricard$ cd ~/Downloads/ruby-1.8.6-p230/ext/readline
iMac:readline ricard$ /opt/ruby/bin/ruby extconf.rb
    checking for tgetnum() in -lncurses... yes
    checking for readline/readline.h... yes
    checking for readline/history.h... yes
    checking for readline() in -lreadline... yes
    checking for rl_filename_completion_function()... yes
    checking for rl_username_completion_function()... yes
    checking for rl_completion_matches()... yes
    checking for rl_deprep_term_function in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_completion_append_character in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_basic_word_break_characters in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_completer_word_break_characters in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_basic_quote_characters in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_completer_quote_characters in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_filename_quote_characters in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_attempted_completion_over in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_library_version in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_event_hook in stdio.h,readline/readline.h,readline/history.h... yes
    checking for rl_cleanup_after_signal()... yes
    checking for rl_clear_signals()... yes
    checking for rl_vi_editing_mode()... yes
    checking for rl_emacs_editing_mode()... yes
    checking for replace_history_entry()... yes
    checking for remove_history()... yes
    creating Makefile

NOTE: Ensure all checks end with yes, otherwise build will fail.


READLINE TERMINAL
iMac:readline ricard$ make
iMac:readline ricard$ sudo make install 

Tunning our PATH

Our ruby installation is inside a non standard folder. In order to set ruby binaries on a path and avoid the need of write full path to binary we go to tune a bit our system. Go to READLINE TERMINAL and execute the following instructions.

  
READLINE TERMINAL
iMac:readline ricard$ cd
iMac:~ ricard$ export PATH=/opt/ruby/bin:$PATH # Adds ruby binary folder into the path for the current session
iMac:~ ricard$ echo export PATH=/opt/ruby/bin:$PATH >> .profile # Adds previous instruction to current user .profile file so 
                                                                # ruby binary folder is loaded automatically into path

0 Responses to “Building ruby on Mac OS X Leopard”


Comments are currently closed.