Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Globally available Gemfile

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.

like image 539
Undistraction Avatar asked Dec 06 '13 10:12

Undistraction


People also ask

Where is Gemfile located?

The Gemfile is wherever you want it to be - usually in the main directory of your project and the name of the file is Gemfile . It's convenient to have one because it allows you to use Bundler to manage which gems and which versions of each your project needs to run.

What is the difference between Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.

Is Gemfile lock automatically generated?

Gemfile. lock is automatically generated when you run bundle install or bundle update . It should never be edited manually.

How do I get Gemfile?

A gemfile is automatically created when you start a new rails application. type rails new appName and then it will be generated automatically. It will also be populated with some gems.


2 Answers

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
like image 129
Casper Avatar answered Sep 22 '22 22:09

Casper


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
like image 31
Undistraction Avatar answered Sep 23 '22 22:09

Undistraction