rvm: ruby version manager 简介

来源:互联网 发布:ubuntu如何编译c 编辑:程序博客网 时间:2024/05/18 17:03

最近越来越发现RVM的好用和方便之处。

rvm能够让你轻松的选择ruby开发的环境。开发过ruby的都知道ruby和rails的版本的变化非常大,比如当前你再ruby-1.9.2下做开发,想体验一下ruby 1.9.3,然后又不想破坏当前的ruby环境,那么rvm就非常有用了。

或者一个项目使用1.9.2的版本,一个项目使用1.9.3的版本,那么在这两个项目之间进行切换,就使用rvm可以方便的做到版本切换。

同时 rvm还可以帮助我们在线安装ruby,rails等。

通过:

rvm use 1.9.3就可以选定需要使用的ruby版本。

Cut Rubies with ease!

w00t!

 

RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby          environments from interpreters to sets of gems.

RVM is maintained by the community through pull requests sent to the project          repository which is located on github at                     https://github.com/wayneeseguin/rvm

RVM is supported by the community via either the (google group)                      Mailing List                    or more real time help via gracious users in the the RVM IRC channel                     #rvm on irc.freenode.net

RVM  lets you deploy each project with its own completely self-contained and dedicated environment,          from the specific version of ruby, all the way down to the precise set of required gems to run your          application. Having a precise set of gems also avoids the issue of version conflicts between          projects, which can cause difficult-to-trace errors and hours of hair loss. With RVM, NO OTHER          GEMS than those required are installed. This makes working with multiple complex applications, where          each has a long list of gem dependencies, much more efficient. RVM let you easily test gem upgrades,          by switching to a new clean set of gems to test with, while leaving your original set intact.          It is flexible enough to even let you maintain a set of gems per environment, or per development          branch, or even per individual developer's taste!

 

RVM reduces the complexity of the many facets of ruby development through          its command-line API.  With RVM, you can have **identical** self-contained          environments in your Development, CI, Q/A, Staging, and Production environments.          No more hidden gotchas: if it works for one of them, it will work in all of them.          With named gemsets, you can reliably and immediately push changes from one environment to another.          And, RVM is for Ruby applications, *not just for Rails*!         Any          Ruby based application will benefit from your use of RVM.

 

RVM enables you to easily test both upgrade and escape paths very easily and consistently.          With RVM, you can run a test suite, rake tasks, benchmarks and gem commands against multiple ruby          versions         at the same time.          This means that you can easily ensure your applications work in Ruby 1.8.X, REE, MRI 1.9.1, jruby,          etc... and quickly expose any areas in which they do not.

 

RVM has an extremely flexible gem management system called Named Gem Sets. RVM's 'gemsets' make          managing gems across multiple versions of Ruby a non-issue. RVM lets you add a small text file to          your application's repository, instead of checking in tons of gems which would needlessly inflate          your repository size. Additionally, RVM's gemset management uses a common cache directory, so only          one downloaded version of each gem resides on disk rather than several copies.       

          RVM helps ensure that all aspects of Ruby are completely contained within user space, strongly          encouraging safer, non-root use. Use of RVM rubies thus provides a higher level of system security,          and therefore reduces risk and cuts overall system downtime. Additionally, since all processes run at          the user level, a compromised ruby process cannot compromise the entire system.

 

 

 

Installing RVM

Install RVM with ruby:       

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

        Additionally with rails:       

$ curl -L https://get.rvm.io | bash -s stable --rails

        Or with rubinius, rails and puma:       

$ curl -L https://get.rvm.io | bash -s stable --ruby=rbx --gems=rails,puma

        Finally, to install without the "rubygems-bundler" or "rvm" gems:       

$ curl -L https://get.rvm.io | bash -s stable --without-gems="rvm rubygems-bundler
 

There are three different ways to install and configure RVM.

  1. Single-User installations (recommended) - For an isolated install within a user's $HOME
  2. Multi-User installations - For server administrators - For an installation usable by all users on the system - Please note that Single-User supercedes Multi-User. This also used to be called the System-Wide Install. Using this type of installation without knowledge how umask works is a big security risk.
  3. Mixed mode installations - For an installation usable by all users on the system - with isolated rubies/gemsets within a user's $HOME. Installation instructions are exactly the same as for Multi-User installations, the difference is in users environment.
 

I recommend you read the installation script yourself. This will give you a chance to understand what it is doing before installing, and allow you to feel more comfortable running it if you do so.

1. Download and run the RVM installation script

Installing the stable release version:

user$ curl -L https://get.rvm.io | bash -s stable

To get the latest development state:

user$ curl -L https://get.rvm.io | bash

For a Multi-User install you would execute the following:

user$ curl -L https://get.rvm.io | sudo bash -s stable
Note: The Multi-User install instructions must be prefixed with the 'sudo' command. However, once the install is complete, and the instructions to add users to the rvm group is followed, the use of either sudo or rvmsudo is no longer required. The 'sudo' command is only to temporarily elevate privileges so the installer can complete it's work. If you need to use 'sudo' or 'rvmsudo' after the install is complete, some part of the install directions were not properly followed. This usually is because people execute the install as root, rather than executing the installation instructions from a non-privileged user account.

Installing a specific version:

user$ curl -L https://get.rvm.io | bash -s -- --version latestuser$ curl -L https://get.rvm.io | bash -s -- --branch [owner/][repo]
Prefix the 'bash' portion with 'sudo', of course, if you wish to apply this to a Multi_user Install. Please feel free to check out our upgrading docs for more details on branch format.

Debugging installation process:

user$ curl -L https://get.rvm.io | bash -s -- --trace

If the rvm install script does nothing or complains about certificates you can bypass this by adding a '-k' switch to the curl command:

user$ curl -kL https://get.rvm.io | bash -s stable

Single-User Install Location: ~/.rvm/

If the install script is run as a standard, non-root user, RVM will install into the current users's home directory.

Multi-User Install Location: /usr/local/rvm

If the install script is run prefixed with sudo, RVM will automatically install into /usr/local/rvm Please see the troubleshooting page for an important note regarding Multi-User Installs.

Please see the FAQ page for an important note regarding root only installs

External tutorials

Note that that any outside tutorials are NOT supported whether they work or not. Tutorials are great, however we have spent massive amounts of man hours debugging the installation process. Please use the install process(es) from this site only, as this is the only supported installation types and methods.

To update an existing RVM installation

It is safe to simply re-run the installation script again, or you can follow the upgrading docs.

 
 

2. Load RVM into your shell sessions as a function

Single-User:

The rvm function will be automatically configured for every user on the system if you install as single user. Read the output of installer to check which files were modified.

Multi-User:

The rvm function will be automatically configured for every user on the system if you install with sudo. This is accomplished by loading /etc/profile.d/rvm.sh on login. Most Linux distributions default to parsing /etc/profile which contains the logic to load all files residing in the /etc/profile.d/ directory. Once you have added the users you want to be able to use RVM to the rvm grou p, those users MUST log out and back in to gain rvm group membership because group memberships are only evaluated by the operating system at initial login time. Zsh not always sources /etc/profile so you might need to add this in /etc/**/zprofile:

source /etc/profile

Mixed mode (user gemsets):

  • Above instructions for Multi-User apply, additional configuration is needed for every user (or in /etc/skel)
  • Select a user as a manager, and add him to rvm group - he will be responsible for installing new rubies.
  • For every user (except the manager user identified above) run:
    rvm user gemsets
 

3. Reload shell configuration & test

Close out your current shell or terminal session and open a new one (preferred). You may load RVM with the following command:

user$ source ~/.rvm/scripts/rvm

If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command which should output 'rvm is a function' as shown below.

user$ type rvm | head -n 1rvm is a function

Finally, see if there are any dependency requirements for your operating system by running:

user$ rvm requirements
 
 

Try out your new RVM installation

Below are some examples of how to install and use a Ruby under RVM.

Display a list of all "known" rubies. NOTE: RVM can install many more Rubies not listed.

user$ rvm list known# MRI Rubies...[ruby-]1.8.7[-p334][ruby-]1.8.7-head...[ruby-]1.9.2[-p180][ruby-]1.9.2-headruby-head# JRubyjruby-1.2.0...

Install a version of Ruby (eg 1.9.2):

user$ rvm install 1.9.2Installing Ruby from source to: /Users/user/.rvm/rubies/ruby-1.9.2-p180, this may take a while depending on your cpu(s)...ruby-1.9.2-p180 - #fetchingruby-1.9.2-p180 - #downloading ruby-1.9.2-p180, this may take a while depending on your connection......ruby-1.9.2-p180 - #extracting ruby-1.9.2-p180 to /Users/user/.rvm/src/ruby-1.9.2-p180ruby-1.9.2-p180 - #extracted to /Users/user/.rvm/src/ruby-1.9.2-p180ruby-1.9.2-p180 - #configuringruby-1.9.2-p180 - #compilingruby-1.9.2-p180 - #installing...Install of ruby-1.9.2-p180 - #complete

Use the newly installed Ruby:

user$ rvm use 1.9.2Using /Users/user/.rvm/gems/ruby-1.9.2-p180

Check this worked correctly:

user$ ruby -vruby 1.9.2p180 (2011-02-18 revision 30909) [i386-darwin9.8.0]user$ which rubyUsing /Users/user/.rvm/gems/ruby-1.9.2-p180/bin/ruby

Optionally, you can set a version of Ruby to use as the default for new shells. Note that this overrides the 'system' ruby:

user$ rvm use 1.9.2 --default

Enjoy using RVM!

原创粉丝点击