Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reinstall every gem for each ruby version?

Tags:

I just installed Ruby 2.0.0 using rbenv and set it to the global ruby version for my system. Since 2.0 is compatible with 1.9.3, I tried to start up a Rails project with it, but got the following error. I did rbenv rehash after installing 2.0

The `rails' command exists in these Ruby versions:
  1.9.3-p327

Does this mean that every gem I installed on my system with 1.9.3 has to be reinstalled if I wish to use it with 2.0?

like image 523
BrainLikeADullPencil Avatar asked Mar 10 '13 20:03

BrainLikeADullPencil


People also ask

How do I install specific versions of gems?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.

How do I uninstall and reinstall a gem?

If you've installed into ./bundle/vendor or similar, you need to remove the gem first but explicitly specify the GEM_HOME, e.g. This is by far the simplest way to uninstall gems installed using bundler into a vendor directory. Ideally, there would be a command bundle uninstall or bundle reinstall , etc.

How do you clean RubyGems?

To remove older gems we use the clean command: The cleanup command removes old versions of gems from GEM_HOME that are not required to meet a dependency. If a gem is installed elsewhere in GEM_PATH the cleanup command won't delete it. If no gems are named all gems in GEM_HOME are cleaned.

How do I use RubyGem's gem install command?

In this guide, we'll cover the basics of RubyGem's gem install command. You may already be familiar with gem install, but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators. gem install mypackage -v '>= 1.0.0' # or gem install mypackage -v '~> 1.0.0'

How do I switch between rails and Ruby versions?

Now that your environments are set up, you can simply switch between Rails versions and Ruby versions as follows. If you are deploying to a server, or you do not want to wait around for rdoc and ri to install for each gem, you can disable them for gem installs and updates. Just add the following line to your ~/.gemrc or /etc/gemrc: Warning!!!

What is the default installation prefix for a ruby gem?

Your gem installation prefix will either be the default e.g. ~/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0 or something you set e.g. .vendor Clear out the gem directory: Show activity on this post.

How do I uninstall a gem from a bundle?

If you've installed into ./bundle/vendor or similar, you need to remove the gem first but explicitly specify the GEM_HOME, e.g. This is by far the simplest way to uninstall gems installed using bundler into a vendor directory. Ideally, there would be a command bundle uninstall or bundle reinstall, etc.


2 Answers

As seen here:

You need to reinstall bundler for each version of Ruby you use. See Ruby versions where you have it installed:

rbenv whence bundle

See your current version:

rbenv version

Install bundler for that version, if missing:

gem install bundler
like image 148
Adam Barthelson Avatar answered Jan 11 '23 04:01

Adam Barthelson


Yes. Rbenv (and RVM) have separate "gem home" directories for each installed version of Ruby. There may be ways to symlink certain directories to get them to share, but this will likely lead to problems, particularly with gems that include native C extensions, which may or may not compile and run cleanly in multiple versions.

If you have a Gemfile, easiest thing is to just bundle install again for Ruby 2.0, giving you duplicate copies of many gems and Ruby-2.0 compiled versions of any native gems.

like image 27
Patrick Avatar answered Jan 11 '23 03:01

Patrick