I added the following code in my .bashrc
But first I should mention I installed 1.8 and 1.9 from macports.
rbv=$("ruby" -v)
rv=${rbv:5:3}
case $rv in
1.8)
export GEM_HOME=/opt/local/lib/ruby/gems/1.8
export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.8:~/lib/rubygems
export PATH=~/bin:$PATH
;;
1.9)
export GEM_HOME=/opt/local/lib/ruby1.9/gems/1.9
export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.9:~/lib/rubygems
export PATH=~/bin:$PATH
;;
*)
;;
esac
Now when I swap from one version to the other all of my environment variables are pointingrv=${rbv:5:3}
case $rv in
1.8)
export GEM_HOME=/opt/local/lib/ruby/gems/1.8
export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.8:~/lib/rubygems
export PATH=~/bin:$PATH
;;
1.9)
export GEM_HOME=/opt/local/lib/ruby1.9/gems/1.9
export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.9:~/lib/rubygems
export PATH=~/bin:$PATH
;;
*)
;;
esac
to the correct place. I've also updated my set_ruby script, here is:
#!/usr/bin/env bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
rbv=$("ruby" -v)
rv=${rbv:5:3}
function r18 () {
ln -s /opt/local/bin/erb1.8 /opt/local/bin/erb
ln -s /opt/local/bin/gem1.8 /opt/local/bin/gem
ln -s /opt/local/bin/irb1.8 /opt/local/bin/irb
ln -s /opt/local/bin/rake1.8 /opt/local/bin/rake
ln -s /opt/local/bin/rdoc18 /opt/local/bin/rdoc
ln -s /opt/local/bin/ri1.8 /opt/local/bin/ri
ln -s /opt/local/bin/ruby1.8 /opt/local/bin/ruby
ln -s /opt/local/bin/testrv1.8 /opt/local/bin/testrb
export GEM_HOME=/opt/local/lib/ruby/gems/1.8
export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.8:~/lib/rubygems
}
function r19 () {
ln -s /opt/local/bin/erb1.9 /opt/local/bin/erb
ln -s /opt/local/bin/gem1.9 /opt/local/bin/gem
ln -s /opt/local/bin/irb1.9 /opt/local/bin/irb
ln -s /opt/local/bin/rake1.9 /opt/local/bin/rake
ln -s /opt/local/bin/rdoc1.9 /opt/local/bin/rdoc
ln -s /opt/local/bin/ri1.9 /opt/local/bin/ri
ln -s /opt/local/bin/ruby1.9 /opt/local/bin/ruby
ln -s /opt/local/bin/testrb1.9 /opt/local/bin/testrb
export GEM_HOME=/opt/local/lib/ruby/gems/1.9
export GEM_PATH=$GEM_HOME:/Users/luis/.gem/ruby/1.9:~/lib/rubygems
}
function cleanruby () {
rm /opt/local/bin/erb
rm /opt/local/bin/gem
rm /opt/local/bin/irb
rm /opt/local/bin/rake
rm /opt/local/bin/rdoc
rm /opt/local/bin/ri
rm /opt/local/bin/ruby
rm /opt/local/bin/testrb
}
if [ $# -eq 1 ]
then
case $1 in
clean)
cleanruby
exit
;;
1.8)
r18
exit
;;
1.9)
r19
exit
;;
*)
echo "+----------------------------------------------------+"
echo "| Either do not use any paramaters or use: |"
echo "| clean, 1.8 or 1.9 |"
echo "+----------------------------------------------------+"
exit
;;
esac
else
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
fi