http://blog.csdn.net/abbuggy/article/details/8170899

RVM的主要作用是友善的管理系統中的多個ruby版本而不至于混亂。
我們來看看如何安裝RVM,我使用的ubuntu12.04LTS。
準備工作
後面需要使用curl,用dpkg -s curl指令檢查一下系統中有沒有安裝
[email protected]:~$ dpkg -s curl
Package: curl
Status: install ok installed
Priority: optional
Section: web
Installed-Size: 338
Maintainer: Ubuntu Developers <[email protected]>
Architecture: i386
Version: 7.22.0-3ubuntu4
Replaces: curl-ssl
Provides: curl-ssl
Depends: libc6 (>= 2.7), libcurl3 (>= 7.16.2-1), zlib1g (>= 1:1.1.4)
Description: Get a file from an HTTP, HTTPS or FTP server
curl is a client to get files from servers using any of the supported
protocols. The command is designed to work without user interaction
or any kind of interactivity.
.
curl offers a busload of useful tricks like proxy support, user
authentication, FTP upload, HTTP post, file transfer resume and more.
Homepage: http://curl.haxx.se
Original-Maintainer: Ramakrishnan Muthukrishnan <[email protected]>
上面的會先說明我是已經安裝過了的,如果沒有安裝應該是類似如下的回顯。
[email protected]:~$ dpkg -s curl
系統沒有安裝軟體包 curl,因而沒有相關的資訊。
使用 dpkg --info (= dpkg-deb --info) 來檢測打包好的檔案,
還可以通過 dpkg --contents (= dpkg-deb --contents) 來列出它們的内容。
那麼安裝就行了sudo apt-get install curl
安裝rvm
用rvm官方推薦的方式安裝curl -L get.rvm.io | bash -s stable
回顯提示我們,RVM被安裝在$HOME/.vrm中;并且需要在終端中加載腳本$HOME/.rvm/scripts/rvm
[email protected]:~$ curl -L get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 185 100 185 0 0 144 0 0:00:01 0:00:01 --:--:-- 906
100 10235 100 10235 0 0 3929 0 0:00:02 0:00:02 --:--:-- 10888
Downloading RVM from wayneeseguin branch stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 131 100 131 0 0 62 0 0:00:02 0:00:02 --:--:-- 143
100 1124k 100 1124k 0 0 127k 0 0:00:08 0:00:08 --:--:-- 269k
Installing RVM to /home/abbuggy/.rvm/
RVM PATH line found in /home/abbuggy/.bashrc /home/abbuggy/.zshrc.
RVM sourcing line found in /home/abbuggy/.bash_profile /home/abbuggy/.zprofile.
# RVM: Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm/
# Screencast: http://screencasts.org/episodes/how-to-use-rvm
# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'
Installation of RVM in /home/abbuggy/.rvm/ is almost complete:
* To start using RVM you need to run `source /home/abbuggy/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.
# abbuggy,
#
# Thank you for using RVM!
# I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne
應該請把這句話加在$HOME/.bash_profile檔案中,以便在開啟一個終端會話時候加載RVM
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
如果對shell變成不熟悉,這裡簡單解釋一下這是幹什麼用的。
[[condition]],兩層的方括号中間括着條件傳回條件是不是真。-s是判斷給定的檔案是否存在的指令。這樣一來,不就是在[[ -s "$HOME/.vrm/scripts/vrm"]]判斷剛才安裝的RVM是否存在嗎?
接下來的&&符号是“短路的與”,目前面的條件是真的時候,執行後面的語句,傳回這兩個語句是不是全是真。在這裡,利用了“短路”特性。也就是說當RVM已經安裝的話,執行後面的. "$HOME/.rvm/scripts/rvm"指令。這條指令和source "$HOME/.rvm/scripts/rvm"是一個意思:加載rvm的啟動腳本。
#符号後面是注釋資訊。
使用RVM
剛才我們通過修改.bash_profile增加的内容需要重新打開終端視窗時加載。我們有兩個選擇,一個是關閉目前的終端視窗重新打開,另一個是在目前視窗執行一遍. "$HOME/.rvm/scripts/rvm"。
察看RVM的版本
[email protected]:~$ rvm -v
rvm 1.16.20 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
通過rvm requirements指令,可以察看安裝各版本時候的前提條件。其中這句是需要關注的。這是安裝依賴的第三方包,沒有這個安裝不成功豈不是很悲劇?
Additional Dependencies:
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
ruby: /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
這樣一來,安裝ruby的準備工作就完成了。察看目前RVM中已經安裝的ruby版本,現在應該還沒有。
[email protected]:~$ rvm list
rvm rubies
# No rvm rubies installed yet. Try 'rvm help install'.
察看RVM可供安裝的ruby版本
[email protected]:~$ rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7-p370
[ruby-]1.8.7[-p371]
[ruby-]1.9.1[-p431]
[ruby-]1.9.2-p180
[ruby-]1.9.2-p290
[ruby-]1.9.2-p318
[ruby-]1.9.2[-p320]
[ruby-]1.9.2-head
[ruby-]1.9.3-preview1
[ruby-]1.9.3-rc1
[ruby-]1.9.3-p0
[ruby-]1.9.3-p125
[ruby-]1.9.3-p194
[ruby-]1.9.3-p286
[ruby-]1.9.3-[p327]
[ruby-]1.9.3-head
[ruby-]2.0.0-preview1
ruby-head
安裝ruby 1.9.3-head,在不發生歧義的情況下方括号内的東西可以不必敲。
[email protected]:~$ rvm install 1.9.3-head
之後等呀等呀自動安裝了1.8.7和1.9.3
[email protected]:~$ rvm list
rvm rubies
ruby-1.8.7-p371 [ i686 ]
ruby-1.9.3-head [ i686 ]
# Default ruby not set. Try 'rvm alias create default <ruby>'.
選擇1.9.3作為目前的使用版本,并且設定為預設
[email protected]:~$ rvm use ruby-1.9.3-head --default
Using /home/abbuggy/.rvm/gems/ruby-1.9.3-head
設定好之後察看ruby版本
[email protected]:~$ ruby -v
ruby 1.9.3p327 (2012-11-10) [i686-linux]
察看ruby的路徑,就是RVM幫我們安裝的
[email protected]:~$ which ruby
/home/abbuggy/.rvm/rubies/ruby-1.9.3-head/bin/ruby
短路RVM
剛才是用RVM進行ruby版本管理,當然了通過其他管道例如apt-get也可以安裝ruby,可以對RVM設定短路以便使用系統預設的ruby版本。
[email protected]:~$ rvm use system
Now using system ruby.
[email protected]u:~$ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
[email protected]:~$ which ruby
/usr/bin/ruby
解除安裝RVM
不想玩了,我要解除安裝。這個指令會移除$HOME/.rvm目錄下面的所有東西即RVM管理的版本們。
rvm implode
也應該删除$HOME/.bash_profile中增加的相關内容。
圖檔資源來自http://www.vgcats.com/comics/?strip_id=285
http://blog.csdn.net/abbuggy/article/details/8170899