Install and use rvm to manage ruby version in ubuntu

The main role of RVM is to easily manage multiple versions of ruby ​​in the system without cluttering it.
Let's see how to install RVM, I use ubuntu12.04LTS.
Preparations
You need to use curl later, use the dpkg -s curl command to check whether the system has

[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ dpkg -s curl 
Package: curl 
Status: install ok installed 
Priority: optional 
Section: web 
Installed-Size: 338 
Maintainer: Ubuntu Developers  
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 The  

above will first indicate that I have already installed it. If it is not installed, it should be similar to the following echo.


[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ dpkg -s curl 
The system does not have the package curl installed, so there is no relevant information. 
Use dpkg --info (= dpkg-deb --info) to detect packed files, 
and dpkg --contents (= dpkg-deb --contents) to list their contents. 

Then install it sudo apt-get install curl

install rvm
Install curl -L get.rvm.io | bash -s stable in the way officially recommended by rvm. The
echo prompts us that RVM is installed in $HOME/.vrm; and the script $HOME/.rvm/scripts needs to be loaded in the terminal /rvm

[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ 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 

should please add this sentence to the $HOME/.bash_profile file so that when you open a Load RVM during terminal session


[plain] view plaincopy
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. 

If you become unfamiliar with the shell, here is a brief explanation Find out what this is for.

[[condition]], the two square brackets enclose the conditional return condition is true. -s is the command to determine whether the given file exists. In this way, isn't it just [[ -s "$HOME/.vrm/scripts/vrm"]] to judge whether the RVM just installed exists?
The next && symbol is a "short-circuit and". When the previous condition is true, execute the following statement and return whether both statements are true. Here, the "short circuit" feature is utilized. That is to say, when RVM has been installed, execute the following. "$HOME/.rvm/scripts/rvm" command. This command has the same meaning as source "$HOME/.rvm/scripts/rvm": load the startup script of rvm.
The # symbol is followed by comment information.
Using RVM
just now, the content added by modifying .bash_profile needs to be loaded when the terminal window is reopened. We have two options, one is to close the current terminal window and reopen it, and the other is to execute it in the current window. "$HOME/.rvm/scripts/rvm".
View RVM version

[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ rvm -v 
 
rvm 1.16.20 (stable) by Wayne E. Seguin , 

Through the rvm requirements command, you can view the prerequisites for installing each version. This sentence needs attention. This is a third-party package that the installation depends on. Wouldn't it be tragic if the installation was unsuccessful without this?

[plain] view plaincopy
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 

With this, the preparation for installing ruby ​​is complete. Check the ruby ​​version installed in the current RVM, it should not be there yet.


[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ rvm list 
 
rvm rubies 
 
# No rvm rubies installed yet. Try 'rvm help install'. 

View the ruby ​​versions available for RVM installation


[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ 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 

installs ruby ​​1.9.3-head, does not happen In the case of ambiguity, the things in brackets do not need to be typed.


[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ rvm install 1.9.3-head 

wait, wait, 1.8.7 and 1.9.3 are automatically installed


[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ 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 '. 

Select 1.9.3 as the current version and set it as the default


[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ rvm use ruby-1.9.3-head --default 
Using /home/abbuggy/.rvm/gems/ruby-1.9.3-head 

After setting, check the ruby ​​version


[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ ruby ​​-v 
ruby ​​1.9.3p327 (2012-11-10) [i686-linux] Check  the path of ruby, which is the [plain] view plaincopy

installed by RVM for us



abbuggy@abbuggy-ubuntu:~$ which ruby 
​​/home/abbuggy/.rvm/rubies/ruby-1.9.3-head/bin/ruby 

short circuit RVM

just used RVM for ruby ​​version management, of course through other channels such as apt- get can also install ruby, and can short-circuit RVM to use the system default ruby ​​version.

[plain] view plaincopy
abbuggy@abbuggy-ubuntu:~$ rvm use system 
Now using system ruby. 
abbuggy@abbuggy-ubuntu:~$ ruby ​​-v 
ruby ​​1.8.7 (2011-06-30 patchlevel 352) [i686-linux] 
abbuggy@abbuggy-ubuntu:~$ which ruby 
​​/usr/bin/ruby 

uninstall RVM

don't want to play anymore, I want to uninstall. This command will remove everything under the $HOME/.rvm directory ie RVM managed versions.

[plain] view plaincopy
rvm implode 

should also delete related content added in $HOME/.bash_profile.
Image source from http://www.vgcats.com/comics/?strip_id=285
http://blog.csdn.net/abbuggy/article/details/8170899Original

: http://blog.sina.com.cn/s/blog_7984a49701019hb2.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326834895&siteId=291194637