
RVM - Ruby Version Manager
A program for managing versions of Ruby.
What if one project uses Ruby 1.8.7, and the other 1.9.2? What if at the same time you have 2 projects under version 1.9.2, but with different sets of gems? Would you like to have separate gem's for each project?
Main tasks:
1. Physical separation of ruby versions and gemset sets
2. The ability to have multiple versions of ruby and switch between them
3. The ability for each version of ruby to have several gemsets — sets of gem's and switch between them
')
Under the cat will be described:
1. Installing RVM
2. Work with different versions of Ruby
3. Work with gemsets
4. Setting the environment for a separate project using .rvmrc
5. RVM commands that may be helpful
6. Cheat sheet for main RVM teams
1. Installing RVM
1. To install, you will need curl and git (apt-get install git curl)
2
3. After installation, you need to add information about the installed rvm application to bash
# bash , rvm
# ,
% echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function'>>~/.bash_profile
In the $ HOME / .bashrc file, replace the line
[-z "$ PS1"] && return with if [[-n "$ PS1"]]; then since we use if, then put fi at the end of the file, this allows you to run programs in non-interactive mode, and rvm is just an example of such a program
4. Check how the installation went.
% rvm -v
rvm 1.6.20 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]
# rvm,
2. Work with different versions of Ruby
To view all available versions of Ruby for installation
% rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.6-head
[ruby-]1.8.7[-p334]
[ruby-]1.8.7-head
[ruby-]1.9.1-p378
[ruby-]1.9.1[-p431]
[ruby-]1.9.1-head
[ruby-]1.9.2[-p180]
[ruby-]1.9.2-head
ruby-head
# GoRuby
goruby
# JRuby
jruby-1.2.0
jruby-1.3.1
jruby-1.4.0
jruby-1.6.1
jruby[-1.6.2]
jruby-head
Suppose you are working with two versions 1.8.7 for ROR2 and 1.9.2 for ROR3
# 2 Ruby
% rvm install 1.8.7
% rvm install 1.9.2
To see all installed Ruby versions
% rvm list
rvm rubies
ruby-1.8.7-p334 [ i386 ]
ruby-1.9.2-p180 [ i386 ]
Switch to ruby 1.8.7
% rvm use ruby-1.8.7
Using /home/user/.rvm/gems/ruby-1.8.7-p334
Use ruby version 1.9.2 by default.
% rvm use ruby 1.9.2 --default
Using /home/user/.rvm/gems/ruby-1.9.2-p180
% rvm list
rvm rubies
=> ruby-1.9.2-p180 [ i386 ] # "=>" Ruby
ruby-1.8.7-p334 [ i386 ]
3. Work with gemsets
For example, you use Ruby On Rails versions 2 and 3 with Ruby 1.8.7 and for each of them you have your own set of gem's.
Create two different sets of gemsets:
% rvm use 1.8.7@rails2 --create
Using /home/user/.rvm/gems/ruby-1.8.7-p334 with gemset rails2
% rvm use 1.8.7@rails3 --create
Using /home/user/.rvm/gems/ruby-1.8.7-p334 with gemset rails3
% rvm gemset list
gemsets for ruby-1.8.7-p334 (found in /home/slip/.rvm/gems/ruby-1.8.7-p334)
global # gemset
rails2
rails3
% rvm use 1.8.7@rails3 --default # gemset rails3
% rvm gemset list
gemsets for ruby 1.8.7-p334 (found in /home/user/.rvm/gems/ruby-1.8.7-p334)
global
rails2
=> rails3 # rails3
Gemsets can be deleted, cleaned, exported, and imported gems from one gemset to another.
RVM provides the following commands for working with gemsets:
create - create a new gemset
export - export of the list of gems to the default.gems file
import - set gems to the current gemset from the default.gems file
delete - delete gemset
empty - clear gemset
4. Setting the environment for a separate project using .rvmrc
What if you have several projects, each of which uses a different version of gemset? You can of course switch between gemsets manually with the help of
rvm use {rubyversion} @ {gemsetname} , but here RVM also comes to our rescue by doing this part of the work for us.
Create a .rvmrc file in the project root directory. For example, a project uses ruby version 1.8.7 with a gemset projectname.
# .rvmrc
rvm use 1.8.7@projectname
Now when you enter the directory,
cd / home / user / www / projectname - RVM executes the command from the .rvmrc file and you see a similar message on the screen
Using /home/user/.rvm/gems/ruby-1.8.7-p334 with gemset projectname
Thus, you no longer have to think about which gemset uses a particular project and install it manually.
5. RVM commands that may be helpful
1. Completion - allows you to use the tab when working with rvm
To enable, add the line
[[-r $ rvm_path / scripts / completion]] &&. $ rvm_path / scripts / completion to a .bashrc or .bash_profile file, after the line with the rvm connection. Read more here
rvm.beginrescueend.com/workflow/completion2.
rvmreset - reboot RVM
3.
rvm uninstall - remove one or more versions of Ruby, leaving the source code
4.
rvm implode - completely remove the RVM (removes ALL)
6. Cheat sheet for main RVM teams
rvm list known - get a list of all ruby versions available for installation
rvm install 1.9.1 - install ruby version 1.9.1
rvm remove 1.9.2 - remove ruby version 1.9.2
rvm use 1.9.2 - switch to ruby version 1.9.2
rvm use 1.9.2@rails3 --default - install ruby version 1.9.2 with gemset rails3 by default
rvm use system - use the system version of ruby
rvm list - list of installed ruby versions
rvm gemset list - a list of gemsets in the selected version of ruby
rvm use 1.9.2@rails3 --create create gemset rails3 for ruby version 1.9.2
rvm gemset export - export gemset to the default.gems file
rvm gemset import default.gems - set gem's from the list in the defaults.gem file to the current gemset