RVM is a command-line tool that provides a convenient way to manage and switch between multiple versions of Ruby environments.

If you are going to learn Ruby/Rails, RVM is one of the essential tools.

All commands here operate under user permissions, and it is best not to use sudo for any commands.

RVM installation

$ curl -L get.rvm.io | bash -s stable
$ source ~/.bashrc
$ source ~/.bash_profile

Modify RVM’s Ruby installation source to domesticTaobao Mirror Server, which can improve the installation speed

$ sed -i -e 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' ~/.rvm/config/db

Ruby installation and switch

  • List known Ruby versions

    rvm list known
    
  • Install a Ruby version

    RVM install 1.9.3

    The latest 1.9.3 is installed here, and all the items in the RVM List Known list can be used for installation.

  • Use a Ruby version

    RVM use 1.9.3

    If you want to set it to the default version, you can

    RVM use 1.9.3 - default
  • Query Ruby that is already installed

    rvm list
    
  • Uninstall an installed version

    RVM remove 1.9.2

The use of gemset

RVM not only provides an environment where multiple Ruby versions can coexist, but also manages Gemsets on a project-by-project basis.

A Gemset can be thought of as a separate virtual Gem environment, where each Gemset is independent of the other.

For example, if you have two projects on Rails 2.3 and Rails 3, Gemset will help you easily set up two gem development environments and switch between them.

Gemsets are attached to the Ruby version. For example, when you use 1.9.2, you create a Gemset named Rails3. When you switch to 1.8.7, Rails3 does not exist.

  • Establish a gemset

    RVM Use 1.8.7 RVM Gemset Create Rails23
  • You can then set the established Gemset as the current environment

    Use can be used to switch languages, or Gemsets, if they are already installed (or set up). And can be seen in the list command.

    RVM Use 1.8.7 RVM Use 1.8.7@rails23

    All installed gems are then installed under this Gemset.

  • Lists the Gemset for Ruby currently

    rvm gemset list
    
  • Clear the gem in the gemset

    If you want to clear all the gems in a Gemset and reinstall all the gems, you can do this

    RVM gemset empty 1.8.7 @ rails23
  • Delete a GemSet

    rvm gemset delete rails2-3
    

The project automatically loads Gemset

RVM can also automatically load Gemsets.

For example, we have a Rails3.1.3 project that requires version 1.9.3 of Ruby. The whole process could go like this.

RVM install 1.9.3 RVM use 1.9.3 RVM gemset create rails313 RVM use 1.9.3@rails313

Now go to the project directory and create an.rvmrc file.

In this file you can simply add a command:

RVM use 1.9.3 @ rails313

Then whatever your current Ruby Settings are, RVM will load Ruby 1.9.3 and Rails 313 Gemset for you when you CD to the project.

Use RVM to quickly deploy NGINX + Passenger

Install Passenger first

gem install passenger

Then use passenger-install-nginx-module to install and deploy Nginx.

Since root permission is required for this step (because you are compiling NGINX) you can use the rvmsudo thing. (This thing is really a good thing)

rvmsudo passenger-install-nginx-module

It will then let you choose whether to download the NGINX source code automatically compile and install, or choose the NGINX source location.

If you select NGINX to install manually, you can add additional compilation parameters to facilitate custom compilation of NGINX.

Then download and install along the way. The default installation location is /opt/nginx.

Then take a look at nginx.conf, it’s all configured for you, just add the root location (yourapp/public).

When I finished the first installation, I was like, how cool is that?

PS: RVM is a good thing, it is very intelligent, it will tell you why (most) the operation failed, and then it will tell you which Lib you need to install, etc. It is very suitable for beginners and experienced users, it is a must-have medicine for home travel.


contributors

via ruby china wiki