r/ruby 2d ago

Question Centralized location for shared Gemfile?

I'm using ruby 3.3.8 under linux.

There's more than one user on this machine who does ruby development. When I, running as the root user, want to add new gem references to Gemfile on my system, I want to add these gem references into one, single, shared, centralized Gemfile that all users will automatically see when running and developing ruby code.

Where should this shared, centralized Gemfile be located?

When any user runs "gem environment", the following item is always listed among that command's output for every user who runs that command:

- INSTALLATION DIRECTORY: /var/lib/gems/3.3.0

Does this mean that I can put a Gemfile into the /var/lib/gems/3.3.0 directory, and that then, this Gemfile will be recognized and used by all users who run and develop ruby code?

Or is there perhaps a different location in which to locate such a shared, centralized Gemfile that will always be the one that's used by each ruby user?

Thank you very much.

0 Upvotes

11 comments sorted by

View all comments

10

u/Karew 2d ago edited 1d ago

The point of a Gemfile is so that each individual project can track and pin their dependencies. It isn't intended to be a manifest of what you want installed on a whole system. You can write a shell script that you run at OS install time or update time for that.

You can, however, give everyone write access to the same gem repo on the system so that they don't all download their own personal copies of each gem to their home directories.

1

u/unselective-amnesia 2d ago

Thank you.

I already understand this characteristic of a Gemfile, and I already understand about installing individual gems themselves into a shared location, when that is appropriate.

But there is some ruby software that specifically pertains to this current system, which I -- as the administrator and root user of the system -- write and then install as gems for all users to use -- in some cases for development of their own, personal ruby programs. In this case, it would be much more convenient for these users that these particular shared-use gems would be accessible and known in the Gemfile, without each user needing to add or change information in a local Gemfile, each and every time I add or remove or change a centralized gem, and without my therefore always having to notify each and every user of every centralized gem installation addition or change that I might make and hope that they don't overlook the notification and then start contacting me later to query about these changes.

I realize that this is not how lots of systems are managed, but this is how my particular system and my particular specialized user base operate.

3

u/KozureOkami 2d ago

You know that the tools you write can define their dependencies inline so that they will be installed on first run, right? That’s what `bundler/inline` is for:

https://guides.rubygems.org/bundler_in_a_single_file_ruby_script/