How to Update Gems on Production Server

Unable to update gems on production server

The instructions are probably a bit confusing. It's saying that you've modified your Gemfile on your development machine and just pushed those changes rather than running bundle install BEFORE committing the changes.

By running bundle install you will update your Gemfile.lock file. This should be pushed to your server as it's more important than Gemfile. Consider the Gemfile the plans for the Gemfile.lock file.

Always remember to:

  1. Run bundle install if you change your Gemfile, even just to make sure. If it's too slow, pass --local through which forces it to only use local gems to resolve its dependencies.
  2. Commit both the Gemfile and Gemfile.lock file to your repository
  3. Deploy both the Gemfile and Gemfile.lock to your production servers to ensure that they're running the exact same dependencies as your development environment.

Running bundle update by itself can be construed as dangerous that will update all the dependencies of your application. It's mainly dangerous if you don't have solid version numbers specified in the Gemfile. I wrote about it here.

gem server: How to update gems with missing rdoc?

You can generate all rdoc of all of your gem with command :

gem rdoc --all

How to install additional gems with bundler in production environment?

Edit .bundle/config changing BUNDLE_FROZEN: '1' to '0' (or removing it) is enough in order to be allowed by Bundler to manage gems in a deployment environment. Then you can edit the Gemfile, run bundle, restart your application and the custom gems are ready to be used.

If you intend to use them outside of the application runtime (f.e. if you need pry in rails console) restarting the server is not needed.

How to upgrade rubygems

Install rubygems-update

gem install rubygems-update
update_rubygems
gem update --system

run this commands as root or use sudo.

Bundler: You are trying to install in deployment mode after changing your Gemfile

The error message you're getting regarding Gemfile.lock may be because your Gemfile and Gemfile.lock don't agree with each other. It sounds like you've changed something in your Gemfile since you last ran bundle install (or update). When you bundle install, it updates your Gemfile.lock with any changes you've made to Gemfile.

Make sure you run bundle install locally, and check-in to source control your newly updated Gemfile.lock after that. Then try deploying.

Edit: As recognised in the comments, a conditional in the Gemfile resulted in a valid Gemfile.lock on one platform, invalid on another. Providing a :platform flag for these platform-dependent gems in the Gemfile should solve the asymmetry.

Bundler on production server can't find any gems

If you're using capistrano, you need to add the line below to config/deploy.rb

require 'bundler/capistrano'

Unless you add that, capistrano won't run bundle install on the remote server while deploying. It also adds the --deployment option that installs all your gems under shared/bundle, thereby making a nice separated gem environment for your app.

Why can't bundle find gems in production after `bundle --deployment`?

With help from brixen and yorickpeterse on #rubinius, we discovered that the root cause of this chaos was psych above 2.0.8.

#with rbx 2.4.1 and psych 2.0.8
rbx-2.4.1 :003 > YAML.dump({fu: 'bar'})
=> "---\n:fu: bar\n"

but the problem comes when you update versions:

rbx-2.4.1 :005 > YAML.dump({fu: 'bar'})
=> "--- !ruby/hash-with-ivars\nelements:\n :fu: bar\nivars:\n :@entries: !ruby/object:Rubinius::Tuple {}\n :@capacity: 16\n :@size: 1\n :@max_entries: 12\n :@state: &1 !ruby/object:Hash::State\n compare_by_identity: false\n head: &2 !ruby/object:Hash::Bucket\n key_hash: 2112643688174279348\n value: bar\n link: \n state: *1\n key: :fu\n tail: *2\n :@mask: 15\n"

Capistrano emits YAML when it creates .bundle/config. It seems Capistrano can't read the "creative" version of its config file, so it goes back to default values.

Once I installed psych 2.0.6 on my production machine and corrected my gemfile, I was able to deploy successfully.

References

  • Rubinius Ticket
  • Psych Ticket
  • assuming instance variables should be emitted

Updating ruby version with Rbenv but gems apparently not updated

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.



Related Topics



Leave a reply



Submit