0

I have just updated Ruby from version 1.9.3-p448 to 1.9.3-p484 using rbenv on a Ubuntu Production server. The updating seems to be successful. Ruby version shows the latest version I just updated.

However when I look at the gems for this version 1.9.3-p484 under the directory: .rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems.

I only find a few gems in that directory. And when I looked at the directory of the previous version, there is a whole bunch of gems in there. Did I miss a step somewhere in the ruby update process?

Now that I am using the new ruby version, do I need to reinstall all the gems for this version? If so, will running bundle install does the job?

user513951
  • 12,445
  • 7
  • 65
  • 82
Steve Loo
  • 276
  • 1
  • 5
  • 12

2 Answers2

2

In short, yes. Since rbenv maintains a separate directory for each ruby installation, you'll need to run bundle again to install the gems for that ruby.

When you install a gem running under ruby 1.9.3-p448 for example, that gem will be installed only for that ruby. When you switch to another version of ruby, that gem will not be available for use until you install it.

Zajn
  • 4,078
  • 24
  • 39
  • Thanks for the response. You mentioned that when I switch to another version of ruby, the previous version gems will not be available for use for the new version. However I found it strange that I am using the new version and my app is still working fine even though the gems for the new version has not been installed. And if I do a bundle exec gem list in my application, it shows all the previous gems. Just trying to understand why this is so. – Steve Loo Dec 11 '13 at 23:44
  • Out of curiosity, if you run `ruby -v` inside your application's directory, what is the output? If you have previously configured rbenv with `rbenv [global|local] `, that version will still be in use in that directory and its sub-directories. – Zajn Dec 12 '13 at 03:16
  • ruby version is the new version 1.9.3-p484. After installing the new version, I did the rbenv global and rbenv rehash. Which was what puzzled me because I had the new version ruby and not install the gems afresh for this version of ruby, and yet my app is still functioning. Now come to think of it,when I ran bundle exec gem list I believe the gems listed were those in the Gemfile.lock. And if I just run gem list, it will only list what's in the .rbenv/versions/1.9.3-p484... folder. That probably accounts for why the app is still running without new install of gems. – Steve Loo Dec 12 '13 at 03:40
1

Yes, you need to run bundle install for the active ruby version. Please make sure that the active ruby version, and the gemset for the application are set properly. Just do the following (in Linux/MacOS):

$ cat .ruby-version
ruby-1.9.3-p484

$ cat .ruby-gemset
your_app_name

And before gem update, please re-neter into the your application/gem folder.

$ cd ..
$ cd your_app_name

I have an additional note. If your application is a gem, there is no reason to add the .ruby-version, and .ruby-gemset files into the git repository, just add them into .gitignore file. When your application is a rails app, adding the files along with the Gemfile.lock into git repo has make sense, because you fix ruby version, and gem set for web-application to one that are those, which uniquely will work. Also some cloud services like heroku requires Gemfile.lock to be added into a git repo.

Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69