Using gems form other versions of Ruby

Hello,

I am using rbenv to control my Ruby versions and gems. I have multiple
versions of Ruby installed and I was wondering if I have to reinstall my
gem list for each version. This is not for a specific rails or ruby project
it is for my global ruby. For example when I try to use pry in the terminal
I get this error:
"The `pry' command exists in these Ruby versions: 2.0.0-p353 2.1.4"
Is there a way I reuse gems or if I have to reinstall them a way to do it
all at once. I googled around but did not find an answer. I installed
bundler for my new ruby version but when I ran it in my home directory
(where I install gems "gem install <gem>") it says no gemfile found.

Thank you,

mendel

I am using rbenv to control my Ruby versions and gems. I have multiple
versions of Ruby installed and I was wondering if I have to reinstall my
gem list for each version.

Gems that have compiled extensions might not be compatible with different versions of Ruby. I don’t know of a tool that can just copy them over because figuring out if it can be done safely for a given gem between two different rubies is probably harder than just reinstalling said gem.

Is there a way I reuse gems or if I have to reinstall them a way to do it
all at once. I googled around but did not find an answer.

You can dig out the gem packages from existing rubies to reinstall. On my system, they’re kept in `~/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/cache`, and on update to Ruby 2.3.0, I could reinstall them all with:

gem install .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/cache/*.gem

I installed
bundler for my new ruby version but when I ran it in my home directory
(where I install gems "gem install <gem>") it says no gemfile found.

Bundler is more about managing gems for a Ruby project, vs. a Ruby installation. A `Gemfile` is committed to a project repo, and in some cases, so’s the `Gemfile.lock`.

···

On 8 Feb 2016, at 11:37, Mendel Schneerson wrote:

It worked perfectly.

Thank you.

mendel

···

On Mon, Feb 8, 2016 at 11:45 AM, Bryce Kerley <bkerley@brycekerley.net> wrote:

gem install .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/cache/*.gem