Gangmax Blog

RVM

“rvm(Ruby Version Manager)”是用于在一台机器上管理多个不同版本ruby实现的工具。这篇文章的内容主要参考了这里和[这里][rtrvm_url]。

安装被依赖的包

1
2
3
4
5
# From: http://gangmax.github.com/blog/2011/11/24/17-01-16-publish-654/
sudo apt-get install zlib1g-dev libssl-dev
# Maybe these packages are also needed but this command fails on Ubuntu 10.04
# From: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book?version=3.2#sec:install_rubygems
sudo apt-get install libxslt-dev libxml2-dev libsqlite3-dev nodejs

执行安装脚本

1
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

配置本地环境

1
2
3
4
5
6
7
8
# Add the following content in your ".bashrc" file.
# Load RVM function
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
# Add RVM to PATH for scripting
PATH=$PATH:$HOME/.rvm/bin

# Then run the following command:
source ~/.bashrc

安装ruby

1
2
3
4
rvm get head && rvm reload
rvm install 1.9.3 && rvm --default use 1.9.3
rvm list
which gem

安装gem

1
2
gem install rails # or
gem install rails -v 3.2.1

创建gemset

1
2
3
4
5
rvm use 1.9.3@rails3tutorial2ndEd --create --default
# https://rvm.beginrescueend.com/gemsets/listing/
rvm gemset list # list all named gemsets for the current ruby interpreter
rvm gemset list_all # list all named gemsets for all interpreters
rvm gemset use rails3tutorial2ndEd

解决irb异常

–来自[这里][irb_url]。–

1
2
3
4
5
rvm pkg install readline
apt-get install ncurses-dev # Actually the "libncurses5-dev" package will be installed instead.
cd $HOME/.rvm/src/ruby-1.9.2-p0/ext/readline
ruby extconf.rb -- --with-readline-dir="$HOME/.rvm/usr"
make install

–运行完成后,一切正常。需要注意的是:如果你的rvm上有不止一个ruby环境,则需要每个>环境都运行以上命令的后三行。–

Added@20120502:

以上方法在Ubuntu12.04下不能解决问题。最后一步的”make install”结果显示无法make。[这里][so_url]有一个简单的解决方法:

1
gem install rb-readline

Added@20130122

今天我在机器(Ubuntu12.04)上的另外一个账户上安装”sudo apt-get install ruby-rvm”,之后再切换回原有帐户发现原来账号手工安装的rvm不能工作,即使”sudo apt-get remove ruby-rvm”也不行。随后我通过rvm网站提供的方法重新安装rvm:

1
curl -L https://get.rvm.io | bash -s stable --ruby

得到了这样一个错误:

1
2
3
4
5
It looks you are one of the happy Ubuntu users,
RVM packaged by Ubuntu is old and broken,
follow this link for details how to fix:

http://stackoverflow.com/a/9056395/497756

然后在给定的链接中找到具体解决方法:

1
2
3
4
sudo apt-get --purge remove ruby-rvm
sudo rm -rf /usr/share/ruby-rvm /etc/rvmrc /etc/profile.d/rvm.sh
env | grep rvm # Make sure all the rvm related configuration is removed.
curl -L https://get.rvm.io | bash -s stable --ruby # Install rvm again.

The final step is add this line to “~/.bashrc”:

1
source /home/user/.rvm/scripts/rvm 

which is got from the output of the RVM installation:

1
2
To start using RVM you need to run "source /home/user/scripts/rvm"
in all your open shell windows, in rare cases you need to reopen all shell windows.

Done.

[rtrvm_url]: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book?version=3.2#sec:install_ruby “Ruby on Rails Tutorial
[irb_url]: ../../../03/09/resolve-a-ruby-irb-issue/
[so_url]: http://stackoverflow.com/questions/8920574/install-ruby-1-9-3-using-rvm-on-ubuntu

Comments