开发者

Any way to bypass re-downloading installed gems when using rvm?

I'm using rvm with different gemsets and loving it. Only problem I've run into is that as I create new gemsets and pick the gems I want, it seems to take awhile to re-download the gems again. Is there a way to let rvm know to use the gems that are already installed in another gemset?

For example, say I have a gemset named set1 with the wirble gem installed. Now I create a new rvm called set2. If I "gem install wirble" on set2 it appears to download wirble all over again. Any way to make rvm use the version that's already in set1?

Edit 1: Thanks everyone or the replies so far. Just to explain more clearly, what I find odd is when I want to install wirble and the SAME EXACT version is already on my computer, why does "gem install wrible" need to go online and download the same exact thing again? Why not just install from my computer locally (ie. in another gemset that has the exact files I need)

Edit 2: AND I am staying in the same version of ruby. So my example is assuming i'm using ruby 1.9.2. I am ONLY changing the gemset. I don't see why doing a "gem install wirble" needs to download it again just for a different gemset (again, on the 开发者_开发知识库same ruby 1.9.2)


Another option is to use Bundler instead of RVM gem sets. This won't download the gems if they are already on your system, and lets you have a unique set for each application.


That's by design. Keeping them separate is the whole point. (So that using one set doesn't affect the other, etc.)

Perhaps you're using multiple gemsets when you don't need to? For example, instead of using a separate gemset for each rails app, just use one. For example, I use ruby-1.9.2-p0@rails3 for all my rails 3 development.

Or I suppose you can always just manually copy them from one rvm directory to another (~/.rvm/gems/ruby-1.9.2-p0@rails3/gems/ on my system). Of course, this will only work for gems that are being compiled against the same ruby version.


If you're worried about clogging the series of tubes, you may want to see if it's possible to set up a gem server on your own machine using gem server and tell rvm to use that.


Googling "gem install from local cache" turned up this:

http://akitaonrails.com/2011/05/29/rubygems-local-cache-hack

It's basically a caching gem proxy that uses the public gem server as upstream.

A lighter-weight solution:

This one lets you selectively install gems (including their deps):

  1. Switch to a gemset that already has the desired gem installed.
  2. Run "gem env" to get the GEM_PATH specific to the gemset.
  3. cd to that gem path and then the cache folder. Here are all the .gem files.
  4. Without leaving that folder, switch to the gemset where the desired gem should go.
  5. Run gem install as usual, but pass the --local option. The desired gem and its deps should automatically be pulled from the current folder.

If you actually want to copy a gemset run these steps while in the gem path cache. Actually this isn't needed as "rvm gemset copy" doesn't download unless necessary.

  1. Make sure you're switched to the source gemset (from which you will be copying).
  2. Run "rvm gemset export"
  3. Edit the default.gems file and remove comment lines.
  4. Switch to the destination gemset (to which you will be copying).
  5. RUN: gem install --local `cat default.gems`
  6. Optional: delete the default.gems file.


One RVM function that doesn't seem to have been mentioned is copy. This is particularly useful when:

  • you want to make a new gemset B comprised of the majority of gems already in your gemset A

  • Perhaps you want to isolate one gem in particular and compare two versions. Or something.

You can do the following, within whichever ruby version context is appropriate:

rvm gemset copy 1.9.4-p448@old_gemset_name 1.9.3-p448@new_gemset_name

This command will make a new gemset which is an exact clone of the old one, and then you can remove and reinstall the gem in question. I did this with Rspec, removing 2.14.1 to compare with 3.0.0beta, like so:

gem uninstall rspec -v2.14
gem install rspec -v3.0.0.beta1

There were some other uninstalls that went along with that, but you get the idea. The result is I can run two separate test suites, each in their respective directories and using a different Rspec, just by switching gemsets. <3 RVM.

EDIT: got the idea from here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜