简体   繁体   中英

What is the proper way to install a Ruby gem; Using RVM or Bundler?

I am following these instructions: https://github.com/phifty/agraph/blob/master/README.rdoc , and there is a step to install a gem using this command:

gem install agraph

I am new to RoR, but I have RVM and Bundler. I am not sure which I should use. Should I install this using RVM or Bundler? What should be the command?

RVM is Ruby Version Manager. It lets you maintain separate installs of Ruby side-by-side without conflicts, easily. One of the requisites for doing this is keeping gems for each version of Ruby separate since the installers can "toggle" based on which version of Ruby you're running.

Gem is a command that lets you install gems. It's the core of the whole infrastructure – it doesn't call out to a lower-level "packager" to do its work.

Bundler runs "on top" of Gem. It makes managing gem versions easier, much like RVM does for Rubies (versions of Ruby). It'll automatically install gems that aren't installed, so you don't need to explicitly run gem install gem-name before running bundle (or bundle install ).


Gem, Bundler, and RVM all cross paths if you start using RVM's gemsets. They allow you to further isolate and control your environment by creating a separate "gem environment" of sorts. The primary use for this is so that you can keep gems for different projects separate, which aids in managing versions. If you use Bundler, this isn't really as important or useful as in pre-Bundler days where Rails/Sinatra/etc. would require the most recent version of a gem.

Does that answer your question?

If you are using Rails 3 you should put the command in your application Gemfile

gem 'agraph'

then run bundle install . This will take care of dependency resolution and bundling the gem on your production servers when you deploy.

For RVM the only thing you might want to do is set an RVM gemset for your application. You can do this by creating a .rvmrc file in your application directory, which will automatically set the RVM ruby version and gemset when you enter into that directory. You should not manually install gems for your application using RVM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM