How to install gems based on Gemfile.lock (without

2019-09-11 15:07发布

问题:

Usually, people will use bundle install to install gems. But it require Gemfile and Gemfile.lock(optional).

My situation is a little different. I only have Gemfile.lock. So how can I install all these gems based on bundle command.

I tried bundle install --deployment. But I got Could not locate Gemfile error.


OK. I asked this question in bundler github issues. Their member gave me a good answer: https://github.com/bundler/bundler/issues/5293#issuecomment-269978731

For summary -- I CAN NOT DO THAT

I gave up to run bundle install with Gemfile.lock only. But I still need to solve my problem. And in my Gemfile, I don't have any special options like groups, platforms, install conditionals. So I wrote a script(gem) to revert the Gemfile.lock to Gemfile for my docker image.

[SOLVED]

回答1:

You can use deployment mode of a bundler.



回答2:

With only gemfile.lock, you can run

bundle install --deployment 

The only catch is that this command installs gems to the vendor/bundle instead of your normal gem bundle path. it is so because it is expected to be used only in production.

It works well all the same though.



回答3:

Have you tried simply running the gem install directly in your terminal? That way you won't need to use a Gemfile at all.

For example, with the devise gem, you can just run $ gem install devise in your terminal and that will install the devise gem without adding it to your Gemfile.



标签: ruby bundler