Updating ruby version with Rbenv but gems apparent

2019-09-03 04:08发布

问题:

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?

回答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.



回答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.