tag:blogger.com,1999:blog-4831054777333972242024-03-13T15:06:29.272-07:00Ruby 1.9 on LeopardMy experience installing Ruby 1.9 on Mac OS X Leopard.Luishttp://www.blogger.com/profile/10204232331289780257noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-483105477733397224.post-87830903356523536302009-09-06T21:50:00.000-07:002009-09-06T22:03:31.226-07:00Ruby 1.9 on Snow LeopardI think I got this working the way I want it.<br /><br />I added the following code in my .bashrc<br />But first I should mention I installed 1.8 and 1.9 from macports.<br /><br /><div style="text-align: left;">rbv=$("ruby" -v)<br />rv=${rbv:5:3}<br />case $rv in<br /> 1.8)<br /> export GEM_HOME=/opt/local/lib/ruby/gems/1.8<br /> export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.8:~/lib/rubygems<br /> export PATH=~/bin:$PATH<br /> ;;<br /> 1.9)<br /> export GEM_HOME=/opt/local/lib/ruby1.9/gems/1.9<br /> export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.9:~/lib/rubygems<br /> export PATH=~/bin:$PATH<br /> ;;<br /><br /> *)<br /> ;;<br />esac<br /><br /></div>Now when I swap from one version to the other all of my environment variables are pointing<br />to the correct place. I've also updated my set_ruby script, here is:<br /><br />#!/usr/bin/env bash<br />if [[ $EUID -ne 0 ]]; then<br /> echo "This script must be run as root" 1>&2<br /> exit 1<br />fi<br /><br />rbv=$("ruby" -v)<br />rv=${rbv:5:3}<br />function r18 () {<br /> ln -s /opt/local/bin/erb1.8 /opt/local/bin/erb<br /> ln -s /opt/local/bin/gem1.8 /opt/local/bin/gem<br /> ln -s /opt/local/bin/irb1.8 /opt/local/bin/irb<br /> ln -s /opt/local/bin/rake1.8 /opt/local/bin/rake<br /> ln -s /opt/local/bin/rdoc18 /opt/local/bin/rdoc<br /> ln -s /opt/local/bin/ri1.8 /opt/local/bin/ri<br /> ln -s /opt/local/bin/ruby1.8 /opt/local/bin/ruby<br /> ln -s /opt/local/bin/testrv1.8 /opt/local/bin/testrb<br /> export GEM_HOME=/opt/local/lib/ruby/gems/1.8<br /> export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.8:~/lib/rubygems<br />}<br /><br />function r19 () {<br /> ln -s /opt/local/bin/erb1.9 /opt/local/bin/erb<br /> ln -s /opt/local/bin/gem1.9 /opt/local/bin/gem<br /> ln -s /opt/local/bin/irb1.9 /opt/local/bin/irb<br /> ln -s /opt/local/bin/rake1.9 /opt/local/bin/rake<br /> ln -s /opt/local/bin/rdoc1.9 /opt/local/bin/rdoc<br /> ln -s /opt/local/bin/ri1.9 /opt/local/bin/ri<br /> ln -s /opt/local/bin/ruby1.9 /opt/local/bin/ruby<br /> ln -s /opt/local/bin/testrb1.9 /opt/local/bin/testrb<br /> export GEM_HOME=/opt/local/lib/ruby/gems/1.9<br /> export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.9:~/lib/rubygems<br />}<br /><br />function cleanruby () {<br /> rm /opt/local/bin/erb<br /> rm /opt/local/bin/gem<br /> rm /opt/local/bin/irb<br /> rm /opt/local/bin/rake<br /> rm /opt/local/bin/rdoc<br /> rm /opt/local/bin/ri<br /> rm /opt/local/bin/ruby<br /> rm /opt/local/bin/testrb<br />}<br />if [ $# -eq 1 ]<br /> then<br /> case $1 in<br /> clean)<br /> cleanruby<br /> exit<br /> ;;<br /> 1.8)<br /> r18<br /> exit<br /> ;;<br /> 1.9)<br /> r19<br /> exit<br /> ;;<br /> *)<br /> echo "+----------------------------------------------------+"<br /> echo "| Either do not use any paramaters or use: |"<br /> echo "| clean, 1.8 or 1.9 |"<br /> echo "+----------------------------------------------------+"<br /> exit<br /> ;;<br /> esac<br />else<br /> if [ ${rv} = 1.8 ]; then<br /> echo "Current version is 1.8 swaping to 1.9"<br /> cleanruby<br /> r19<br /> elif [ ${rv} = 1.9 ]; then<br /> echo "Current version is 1.9 swapping to 1.8"<br /> cleanruby<br /> r18<br /> fi<br />fiLuishttp://www.blogger.com/profile/10204232331289780257noreply@blogger.com0tag:blogger.com,1999:blog-483105477733397224.post-25806162501761303432009-07-30T09:41:00.000-07:002009-07-30T15:18:50.079-07:00The pain of getting ruby 1.9 to work in Mac OS XI consider my self a perpetual learner and novice of computer science. That is why if you see one my question in one the 100k forums out there I will be the newbie asking a question.<br /><br />I like ruby, it is an easy to learn scripting language that I find fun to play with and supper handy. Years ago, I considered scripting languages to be either a joke or strictly a system-admin tool. After all I am a C language old fart programmer that start learning computer programing in 1980.<br /><br />Back then... well, it is all being said by many.<br /><br />Nowadays with better technology some scripting languages have a chance to be as popular as C is today to do low-level tasks and maybe be part of an os like sh, bash, tsh , etc.<br /><br />Anyway, back to the pain of upgrading ruby in OS X. After some research I could not find an easy one stop do it all, way to upgrade to ruby 1.9. At one point I end up messing up most of the default ruby installation.<br />I did find a method that worked for me at :<br /><a href="http://bparanj.blogspot.com/2008/03/installing-ruby-19-on-mac-os-x-with.html">http://bparanj.blogspot.com/2008/03/installing-ruby-19-on-mac-os-x-with.html<br /></a>This procedure could use some cleanup but it worked!!!<br />I am going to share with you what I end up doing so anyone can use this procedure by executing<br />a script.<br />The script will download the necessary files in to /tmp and work in this directory.<br />There is also a second script that it swap all the necessary files from the current version<br />already installed on your system to the new one.<br /><br /><ol style="font-family: courier new;"><li>#!/usr/bin/evn bash</li><li>#Initial development: Luis E. McDougall</li><li>#Date :7/30/2009</li><li>#Do what ever you want with this code</li><li>#Intended for Mac OS X leopard</li><li>cd /tmp</li><li>#download readline and patch - compile and install </li><li>curl -O ftp://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz</li><li>tar xzvf readline-5.2.tar.gz</li><li>cd readline-5.2</li><li>curl -O http://ftp.gnu.org/gnu/readline/readline-5.2-patches/readline52-012</li><li>patch -p0 <></li><li>./configure --prefix=$HOME/</li><li>make</li><li>sudo make install</li><li>cd ..</li><li>#download and install latest version of ruby.</li><li>rm index.ht*</li><li>wget -F ftp://ftp.ruby-lang.org/pub/ruby/1.9/</li><li># I am only interesting in the tar.gz files</li><li># you can go crazy and do a less/more cryptic regex here.<br /></li><li>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'</li><li>echo -n "please enter a file from the above list:"</li><li>read -e Ruby_File</li><li>curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.9/$Ruby_File</li><li>tar xzvf {$Ruby_File}</li><li>#since we are working in /tmp</li><li>#I am asuming there is no previous </li><li>#directories with namme ruby.....</li><li>cd ruby*</li><li>autoconf</li><li>sudo ./configure --prefix=$HOME/ruby19 --with-readline-dir=$HOME/</li><li>sudo make</li><li>sudo make install</li></ol>Now I have safely installed ruby1.9 in a place where it does not disturb the original ruby.Yo can change where to install ruby by replace $HOME to whatever directory you want.<br /><br />The next script allows me to swap default version. Instead of changing the path I re-build the<br />links every time. I should mention that rake in my system is in /usr/bin and I had to adjust<br />my script to take care of that.<br /><br /><ol><li><span style="font-family:courier new;">#!/usr/bin/env bash</span></li><li><span style="font-family:courier new;">rbv=$(ruby -v)</span></li><li><span style="font-family:courier new;">rv=${rbv:5:3}</span></li><li><span style="font-family:courier new;">function r18 () {</span></li><li><span style="font-family:courier new;"> ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/erb /usr/bin/erb </span></li><li><span style="font-family:courier new;"> ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem /usr/bin/gem </span></li><li><span style="font-family:courier new;"> ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/irb /usr/bin/irb </span></li><li><span style="font-family:courier new;"> ln -s /usr/bin/rake.1.8 /usr/bin/rake </span></li><li><span style="font-family:courier new;"> ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/rdoc /usr/bin/rdoc </span></li><li><span style="font-family:courier new;"> ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ri /usr/bin/ri </span></li><li><span style="font-family:courier new;"> ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby /usr/bin/ruby </span></li><li><span style="font-family:courier new;"> ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/testrb /usr/bin/testrb </span></li><li><span style="font-family:courier new;">} </span></li><li><span style="font-family:courier new;"> </span></li><li><span style="font-family:courier new;">function r19 () {</span></li><li><span style="font-family:courier new;"> ln -s /Users/luis/ruby1.9/bin/erb /usr/bin/erb </span></li><li><span style="font-family:courier new;"> ln -s /Users/luis/ruby1.9/bin/gem /usr/bin/gem </span></li><li><span style="font-family:courier new;"> ln -s /Users/luis/ruby1.9/bin/irb /usr/bin/irb </span></li><li><span style="font-family:courier new;"> ln -s /Users/luis/ruby1.9/bin/rake /usr/bin/rake </span></li><li><span style="font-family:courier new;"> ln -s /Users/luis/ruby1.9/bin/rdoc /usr/bin/rdoc </span></li><li><span style="font-family:courier new;"> ln -s /Users/luis/ruby1.9/bin/ri /usr/bin/ri </span></li><li><span style="font-family:courier new;"> ln -s /Users/luis/ruby1.9/bin/ruby /usr/bin/ruby </span></li><li><span style="font-family:courier new;"> ln -s /Users/luis/ruby1.9/bin/testrb /usr/bin/testrb </span></li><li><span style="font-family:courier new;">}</span></li><li><span style="font-family:courier new;">function cleanruby () {</span><span style="font-family:courier new;"> </span></li><li><span style="font-family:courier new;">rm /usr/bin/erb </span></li><li><span style="font-family:courier new;">rm /usr/bin/gem </span></li><li><span style="font-family:courier new;">rm /usr/bin/irb </span></li><li><span style="font-family:courier new;">rm /usr/bin/rake </span></li><li><span style="font-family:courier new;">rm /usr/bin/rdoc </span></li><li><span style="font-family:courier new;">rm /usr/bin/ri </span></li><li><span style="font-family:courier new;">rm /usr/bin/ruby </span></li><li><span style="font-family:courier new;">rm /usr/bin/testrb</span></li><li><span style="font-family:courier new;">}</span></li><li><span style="font-family:courier new;">if [ ${rv} = 1.8 ]; then</span></li><li><span style="font-family:courier new;"> echo "Current version is 1.8 swaping to 1.9"</span></li><li><span style="font-family:courier new;"> cleanruby</span></li><li><span style="font-family:courier new;"> r19</span></li><li><span style="font-family:courier new;">elif [ ${rv} = 1.9 ]; then</span></li><li><span style="font-family:courier new;"> echo "Current version is 1.9 swapping to 1.8"</span></li><li><span style="font-family:courier new;"> cleanruby</span></li><li><span style="font-family:courier new;"> r18</span></li><li><span style="font-family:courier new;">fi</span></li><li><span style="font-family:courier new;">exit</span></li></ol><br />I bet that a more experience person can make these scripts fancier and more efficient. But this works and I am not messing with it.<div>By the way, you are going to need xcode from apple to be able to compile any of this code.<br /><br /><br />I like gentoo but I find sabayon to be less painful and this OS have a fantastic way to keep it updated.</div>Luishttp://www.blogger.com/profile/10204232331289780257noreply@blogger.com1