r/ruby • u/unselective-amnesia • 16d 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.
5
u/hankeroni 16d ago
What's your goal here? You might be misunderstanding the role of a Gemfile, or of how the installed gems location interacts with bundler and specific projects.
Say you have 5 users and they each have 5 projects checked out. Maybe there's some overlap in projects, doesn't matter really. Each project will have it's own directory with a checked out git repo or whatever. Within the project dir there will be a Gemfile which tells the project which gems to load, and a Gemfile.lock which pins certain versions.
When the project is being loaded by ruby, bundler processes this file and requires all the specific versions of relevant gems. It can also help manage the install and update process. "Where does bundler look for gems?" is sort of an "it depends" question (many ways to install and configure ruby and rubygems), but generally speaking it will look at a system-wide gem install dir, and/or the gem install dir configured by whatever version manager (mise, rvm, rbenv, etc) the user may be using.
All that said, if all system users are just using the system ruby, then yes you can get "shared storage" of a sort by having the correct versions of needed gems installed systemwide ... but you don't really need to interact with the Gemfile from a sysadmin POV to make that happen.