From: Kaspar Schiess Date: 2009-08-18T15:31:10+09:00 Subject: Re: ruby 1.9 side by side with 1.8 > and i can switch ruby versions with select_ruby script that updates a > symbolic link that points to the active version. Updating a single symbolic link wasn't enough here - I wanted to update gem binaries as well. Here's what I use (and I am sure you can deduce further details from the script)... kaspar -------------- #!/usr/local/share/ruby19/bin/ruby def base_path '/usr/local/share/' end def bin_dir(version) File.join(base_path, version, 'bin') end def lib_dir(version) File.join(base_path, version, 'lib') end def replace_symlink(source, dest) if !File.exists?(dest) || File.symlink?(dest) print "[#{File.basename(dest)}] " `sudo ln -nsf #{source} #{dest}` end end # Iterates over binaries in version. # def all_binary_links(version) # yield: binary_path, symlink_path Dir[File.join(bin_dir(version), '*')].each do |binary_path| binary_name = File.basename(binary_path) yield binary_path, File.join('/usr/bin', binary_name) end end def switch_to(ruby_version, old_version) # Remove current (old) symlinks puts "Removing old links..." all_binary_links(old_version) do |bin_path, link_path| print '.' `sudo rm #{link_path} 2>/dev/null` end puts puts "Symlinking new version..." all_binary_links(ruby_version) do |bin_path, link_path| replace_symlink(bin_path, link_path) end puts # Symlink /lib replace_symlink( lib_dir(ruby_version), '/usr/lib/ruby') puts end case ARGV.first when /19/ switch_to :ruby19, :ruby18 when /18/ switch_to :ruby18, :ruby19 else puts "Run with either '19' or '18' to switch to the given ruby version..." end