Question

I have numerous gems that I use across all Rails projects, but that aren't part of the projects' Gems, for example powder for managing POW.

It would make sense to me to manage these with a global Gemfile, but I can't see any examples of this.

How should I manage global Gems that I don't want in my project gemfiles? It would be good to have a single point of install for when I set up a new machine etc.

I'm using chruby alongside ruby-install to manage my Ruby versions.

Was it helpful?

Solution

Make a Gemfile as usual, and place it in any folder. It does not need to be a project folder. Then you can just do:

bundle install --system

This will install the gems in the Gemfile system-wide, and will ask for the root password if you do not have access to the system folder.

--system: Installs the gems in the bundle to the system location. This overrides any previous remembered use of --path.

You can also name your Gemfile(s), if you want to organize them in some way:

bundle install --system --gemfile=/path/to/my_special_gemfile

OTHER TIPS

As an addition to @Casper's answer:

I created a directory for my system Gem files.

I then added a dir for each version of ruby I wanted to install system gems for. I added a Gemfile to each dir and a .ruby-version file with the correct version. I can now install system gems for a ruby version using:

$ cd path/to/system_gems_dir/1.9.3-p484
$ bundle install --system

or

$ cd cd path/to/system_gems_dir/2.0.0-p353
$ bundle install --system

You can create GlobalGemfile file (or whatever you name it) and than you can do.

bundle install --gemfile GlobalGemfile

Cool isn't it :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top