Is there a way to force an update of the Gemfile.lock without installing the gems that have changed?
- 12,420
- 9
- 82
- 110
-
2Why do you want / have to do that? – Stefan Oct 13 '14 at 08:43
-
1Maybe there's a better way, what exactly you're trying to do? – Surya Oct 13 '14 at 08:44
-
3I am deploying to an external service which requires some specific versions of some gems which won't install on my system. The only way to make the service work is to have a valid Gemfile.lock with the required versions. I could go in and do it manually in the Gemfile.lock, but I would prefere to be able to update it "properly" using bundler. – Automatico Oct 13 '14 at 08:46
-
If I'm not mistaken, Bundler updates gems by installing them. You could either log in to the external service and run `bundle update` there or set up a virtual machine matching your external service locally. – Stefan Oct 13 '14 at 08:50
-
1@Stefan I am afraid that is not possible. The service, Heroku, is not easily virtualised. It works by looking at a git repo which you push to the service, and it sort of bootstraps from there. – Automatico Oct 13 '14 at 08:55
-
You should submit a support ticket. From Heroku's [docs](https://devcenter.heroku.com/articles/gems): *"Almost any gem - even those with native dependencies - can be installed using Bundler. If there’s a specific gem that won’t install on Heroku, please [submit a support ticket](https://help.heroku.com/tickets/new)."* – Stefan Oct 13 '14 at 09:05
-
Well, in my case, Rmagick is a gem that is outside of "almost any". They specify that you need version 2.12.0, but that won't install on my machine, thus, I would like to have a valid Gemfile.lock that I can push to Heroku, even though it won't install on my machine. I have got this working by manually changing the Gemfile.lock, but it is not a preferred solution. – Automatico Oct 13 '14 at 09:26
-
Are you sure? https://github.com/andyw8/rmagick-heroku-demo specifies [rmagick (2.13.2)](https://github.com/andyw8/rmagick-heroku-demo/blob/master/Gemfile.lock#L7) and it seems to be running fine. – Stefan Oct 13 '14 at 09:54
-
Strange.. I got an error when I ran `git push heroku master` saying "... You have added to the Gemfile: * rmagick (= 2.12.0) You have deleted from the Gemfile: * rmagick ..." Anyway, I think it would be nice to be able to generate the Gemfile.lock without needing to install everything, though I see that it might require to download all the source to see what depends on what. – Automatico Oct 13 '14 at 11:02
3 Answers
Run bundle lock --update.
I found an answer in a blog post by Chris Blunt: “Rails on Docker: Quickly Create or Update Your Gemfile.lock”:
Today, I discovered a way to save the hours wasted downloading gems: bundler’s lock command.
This gem of a command resolves your app’s dependencies and writes out the appropriate
Gemfile.lock– without installing any of the gems themselves.
According to the changelog, this command was added in Bundler 1.10.0.pre, released about eight months after this question was asked.
- 5,699
- 7
- 38
- 49
-
-
2`bundle lock` without `--update` will add missing gems to the `Gemfile.lock` without doing possibly harmful updates. – RWDJ Dec 28 '19 at 23:12
-
1This is inaccurate. The `--update` flag *will* update the gems. Which is precisely what the question requests **not** to do. – Arnaud Meuret Feb 10 '23 at 06:23
Instead of
bundle install
do the following:
bundle lock
This will just update the Gemfile.lock, but not attempt to install the files locally.
If you want to prepare a Gemfile.lock for a remote or deployment platform you must add it using
bundle lock --add-platform ...
Latest docs at https://bundler.io/v1.16/man/bundle-lock.1.html
- 23,994
- 6
- 61
- 85
UPDATE: This is still supported by the current (2.4) version but has been deprecated in favour of the lock command.
Force your specific requirement using:
bundle inject rmagick "=1.7.1"
- 985
- 8
- 26
-
I can't seem to get this to work. I keep getting "you specified rmagick(_some_version) and rmagick (injected_version)" – Automatico Oct 14 '14 at 10:44
-
In the Gemfile, move your (dev) version to the development group and leave Heroku's in the main section (make sure you deploy to Heroku --without development). – Arnaud Meuret Oct 14 '14 at 12:59
-
1As of at least 2023, the `help` says that `bundle inject` is outdated and should no longer be used. – Jason Hemann Feb 08 '23 at 15:22