Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to override gemfile for local development?

We have a Gemfile currently in our git repository. However, there's a gem I use only locally in my environment (my team doesn't use it). In order to use it, I have to add it to our Gemfile, but every time I check out to our master/dev main branch, I have to remove it because of conflicts with the tracked gemfile.

What I would like is something like a Gemfile.local which would inherit the gems imported from the Gemfile but to also allow new gems to be imported there to use on my machine only. This file would be ignored in .gitignore. Is this even possible?

like image 642
luispcosta Avatar asked Feb 19 '18 10:02

luispcosta


People also ask

Does Gemfile order matter?

Ordering in the Gemfile does not matter as far as I know.

Why do we need Gemfile?

A Gemfile helps us install all the dependencies under a version-controlled environment. This is needed for each group as it can make our lives much easier.

What can you do with Gemfile?

Your gemfile is a list of all gems that you want to include in the project. It is used with bundler (also a gem) to install, update, remove and otherwise manage your used gems. These gems belong to development environment and the test environment since they are for testing the application.

Where is Gemfile stored?

A Gemfile is a file we created which is used for describing gem dependencies for Ruby programs. The Gemfile is located in the root of the project directory.


2 Answers

Set BUNDLE_GEMFILE environment variable:

BUNDLE_GEMFILE=Gemfile.local bundle exec rails c

To provide a “delta” only in the Gemfile.local put require_relative 'Gemfile' on top of it (or Bundler::Dsl#eval_gemfile as suggested by @MichaelKohl in comments.)

like image 124
Aleksei Matiushkin Avatar answered Sep 19 '22 22:09

Aleksei Matiushkin


Put below code at the top of your Gemfile.local to load existing gemfile:

if File.exists?('Gemfile') then
  eval File.read('Gemfile')
end

It will load all gems from existing Gemfile. You can add new gems also as you need.

Run below commands to install gems from new Gemfile.local:

bundle install --gemfile=Gemfile.local
like image 38
Prince Bansal Avatar answered Sep 23 '22 22:09

Prince Bansal