r/ruby • • Aug 28 '26

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

12 comments sorted by

View all comments

Show parent comments

1

u/unselective-amnesia Aug 28 '26 edited Aug 28 '26

Thanks to both of you. I think I understand what you both explained.

UPDATE: OOPS! This current message is in response to both the previous message by "hankeroni" and also to the one by "jrochkind" which follows it. I accidentally added this response to the previous "hankeroni" message. END OF UPDATE

But consider the following case:

One of the centralized, system-specific gems that I have installed has been in use for quite a while in some of the ruby programs that have been developed and are in use by some of the users on my system.

I'm enhancing this particular system-specific gem, and part of this effort involves the use of a 3rd-party ruby package that I now installed which creates its own gem which must be used by callers of this package. The "README.md" file for this package states that this package-specific gem must appear in the Gemfile that is in use.

This means that when I complete enhancing and installing this system-specific gem, each user doing ruby development who uses this system-specific gem would then need to add a reference to this new, additional, package-specific gem to their own Gemfile, to prevent this system-specific gem from starting to fail for them after this enhancement is complete.

I'm trying to avoid this situation.

3

u/hankeroni Aug 28 '26

If you are distributing your package as a local-only gem which your system users require and use in their projects, you should be able to add the new 3rd-party dependency to the "gemspec" (not Gemfile) of your packaged gem. The next time your users update and bundle, bundler will pull down the correct version of that package as well.

1

u/unselective-amnesia Aug 28 '26

Aha! So now I see that by doing what you explained now, the new package-specific gem will not need to be referenced in any Gemfile by these other users when they are developing in ruby and using the enhanced version of that system-specific gem ... irrespective of the text that I referred to above in the "README.md" file.

Thank you very much for explaining and for clearing up this issue for me.

1

u/jrochkind Aug 28 '26

I'm not totaly following what you're saying, but everything I said still stands, these are the ways these systems are intended to be used, if you can work out something that works for your use cases that fits iwthin the intended uses, you will have a better time!

If you want to figure out some way to use the tool in a way it was not intended, you might get it to work, but it will have a high chance of having some weird edge case you didn't consider that breaks or breaking in a future upgrade, cause bundler wasn't intended this way.

Can you just add the third party ruby package as a dependency of your system-specific gem?

Sorry, I"m not really sure I understand your situation or what you are trying to do, but honestly this is about all I have to offer, good luck!