http://www1.ubuntuforums.org/showthread.php?t=1366485
There is actually an easier way. Debian and derivatives such as Ubuntu have a system to handle multiple versions of various apps:
1. install both versions of ruby. note that rubygems is built-in to ruby1.9.1:
Code: sudo aptitude install ruby rubygems ri ruby1.9.1 ri1.9.1
2. remove the alternative which is set up by default for gem:
Code: sudo update-alternatives --remove-all gem
2. set up the ruby alternatives:
Code: sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.8 500 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby1.8.1.gz \
--slave /usr/bin/ri ri /usr/bin/ri1.8 \
--slave /usr/bin/irb irb /usr/bin/irb1.8 \
--slave /usr/bin/gem gem /usr/bin/gem1.8
sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby1.9.1.1.gz \
--slave /usr/bin/ri ri /usr/bin/ri1.9.1 \
--slave /usr/bin/irb irb /usr/bin/irb1.9.1 \
--slave /usr/bin/gem gem /usr/bin/gem1.9.1
now to switch versions you just do:
Code: sudo update-alternatives --config ruby
如若删除链接组中的软连接 /usr/bin/ruby 则运行 sudo update-alternatives --config ruby会自动强制重新安装优先级高的那个版本。
There is actually an easier way. Debian and derivatives such as Ubuntu have a system to handle multiple versions of various apps:
1. install both versions of ruby. note that rubygems is built-in to ruby1.9.1:
Code: sudo aptitude install ruby rubygems ri ruby1.9.1 ri1.9.1
2. remove the alternative which is set up by default for gem:
Code: sudo update-alternatives --remove-all gem
2. set up the ruby alternatives:
Code: sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.8 500 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby1.8.1.gz \
--slave /usr/bin/ri ri /usr/bin/ri1.8 \
--slave /usr/bin/irb irb /usr/bin/irb1.8 \
--slave /usr/bin/gem gem /usr/bin/gem1.8
sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby1.9.1.1.gz \
--slave /usr/bin/ri ri /usr/bin/ri1.9.1 \
--slave /usr/bin/irb irb /usr/bin/irb1.9.1 \
--slave /usr/bin/gem gem /usr/bin/gem1.9.1
now to switch versions you just do:
Code: sudo update-alternatives --config ruby
如若删除链接组中的软连接 /usr/bin/ruby 则运行 sudo update-alternatives --config ruby会自动强制重新安装优先级高的那个版本。