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.
Back then... well, it is all being said by many.
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.
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.
I did find a method that worked for me at :
http://bparanj.blogspot.com/2008/03/installing-ruby-19-on-mac-os-x-with.html
This procedure could use some cleanup but it worked!!!
I am going to share with you what I end up doing so anyone can use this procedure by executing
a script.
The script will download the necessary files in to /tmp and work in this directory.
There is also a second script that it swap all the necessary files from the current version
already installed on your system to the new one.
- #!/usr/bin/evn bash
- #Initial development: Luis E. McDougall
- #Date :7/30/2009
- #Do what ever you want with this code
- #Intended for Mac OS X leopard
- cd /tmp
- #download readline and patch - compile and install
- 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 ..
- #download and install latest version of ruby.
- 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 am asuming there is no previous
- #directories with namme ruby.....
- cd ruby*
- autoconf
- sudo ./configure --prefix=$HOME/ruby19 --with-readline-dir=$HOME/
- sudo make
- sudo make install
The next script allows me to swap default version. Instead of changing the path I re-build 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
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.
By the way, you are going to need xcode from apple to be able to compile any of this code.
I like gentoo but I find sabayon to be less painful and this OS have a fantastic way to keep it updated.
I like gentoo but I find sabayon to be less painful and this OS have a fantastic way to keep it updated.
After more research and play, I end up using port. But all is lost since I am still using my script to switch from one version to the other.
ReplyDelete