mipmip
10/9/2014 - 11:46 AM

Change system ruby version in OS X Mavericks

Change system ruby version in OS X Mavericks

#!/bin/sh

while getopts ":a :b" opt; do
	case $opt in
		a)
			cd /System/Library/Frameworks/Ruby.framework/Versions/
			sudo rm Current
			sudo ln -sf /System/Library/Frameworks/Ruby.framework/Versions/1.8 Current
			sudo rm -rf /usr/bin/ruby
			sudo ln -sf /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby /usr/bin/ruby
			echo "-a set ruby 1.8.7" >&2
			;;
		b)
			cd /System/Library/Frameworks/Ruby.framework/Versions/
			sudo rm Current
			sudo ln -sf /System/Library/Frameworks/Ruby.framework/Versions/2.0 Current
			sudo rm -rf /usr/bin/ruby
			sudo ln -sf /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby /usr/bin/ruby
			echo "-b set ruby 2.0" >&2
			;;
		\?)
			echo "Invalid option: -$OPTARG" >&2
			echo "use -a for 1.8 and -b for 2.9" >&2
			;;
	esac
done
echo "current version:" >&2
/usr/bin/ruby -v