Search code examples
rubygemset

What gems are in the default gemset for Ruby 2.0.0-p247?


By accident I ran rvm gemset empty default.

Can someone list all gems from gemset default for ruby-2.0.0-p247 so I can reinstall them manually?

Thanks!


Solution

  • Don't worry, it's still possible to restore all your gems:

    #!/usr/bin/env bash
    
    CURRENT_GEMSET=$( rvm current )
    CACHE_FOLDER=~/.rvm/gems/$CURRENT_GEMSET/cache
    CACHED_GEMS=$CACHE_FOLDER/*.gem
    
    for gem_file in $CACHED_GEMS
    do
      GEM_FILES=$GEM_FILES' '$gem_file
    done
    
    gem install $GEM_FILES
    

    You may take a look at ~/.rvm/gems/$( rvm current )/cache folder first. All gems should be there.

    Edit:

    rvm gemset empty
    

    Removes all the installed gems for gemset. But gems are still in ~/.rvm/gems/$( rvm current )/cache folder(e.g. ~/.rvm/gems/ruby-2.0.0-p247/cache, ~/.rvm/gems/jruby-1.7.3@my_gemset/cache) and you are still able to install them.

    A bit of explanations regarding script:

    1. rvm current Print the current Ruby version and the name of any gemset being used(from rvm usage current). You may invoke rvm gemset use first in order to choose gemset you want to restore.
    2. ~/.rvm/gems/$( rvm current )/cache is a cache folder for current gemset and is the same as $GEM_HOME/cache.
    3. ~/.rvm/gems/$( rvm current )/cache/*.gem is a regexp for gems in cache folder.
    4. Loop through the file names and concatenate them into a single string

      for gem_file in $CACHED_GEMS
      do
        GEM_FILES=$gem_file' '$GEM_FILES
      done
      
    5. gem install $GEM_FILES reinstalls you gems.