2

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]

agate
  • 956
  • 1
  • 7
  • 13
  • did you consider reading the `gemfile.lock` and reverse-engineering the `gemfile`? Bundler is designed to use gemfiles, I don't recommend you fight it. – Myst Dec 30 '16 at 09:34
  • @Myst I am trying either reverse gemfile.lock -> gemfile OR bundle install directly via gemfile.lock. It's because I only have Gemfile.lock right now. The Gemfile will `require` some external Gemfile in another repo. So when I build my docker image. I only have the generated Gemfile.lock. What should I do? – agate Jan 02 '17 at 07:45
  • maybe download a local copy every time you run the script? – Myst Jan 03 '17 at 05:42

3 Answers3

1

You can use deployment mode of a bundler.

unkmas
  • 977
  • 4
  • 13
0

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.

Cent
  • 871
  • 7
  • 16
  • 1
    I saw this solution in other thread. But when I try to use it. I got error: `Could not locate Gemfile` – agate Dec 30 '16 at 09:00
0

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.

LBarry
  • 115
  • 9
  • I know I can do that. But I am trying to build a docker image. Which I hope I can re-use my local Gemfile.lock. So that I don't have to manually add bunch of gem install commands. – agate Dec 30 '16 at 09:11