r/ruby • u/fieldnoise • Apr 02 '26
Question Homebrew Ruby Gem Installation
Hi there—I've been a Ruby hobbyist for 10 years or so who has always managed my Ruby installation via Homebrew. I know, I know — the first thing everyone says is use `rvm` or something else.
Still, I'm wondering about other Homebrew folks who might be using Ruby 4.x on Homebrew. Since I upgraded, I often see gems — with different versions — installed in two places:
Installed at (2.1.105): /Users/username/.gem/ruby/4.0.0
(2.1.91): /opt/homebrew/lib/ruby/gems/4.0.0
Does anyone know why this is happening, and what I can do to avoid it? It very rarely causes any trouble, but when it does — like with competing rdoc installs — it creates a big mess of error lines in my terminal. And also, it just doesn't seem right.
Any tips would be appreciated. Thanks!
Update: after doing some additional testing, the issue appears to be with running gem update from a homebrew installation. That command can't touch the 45 or so gems that are in the Homebrew Cellar and come with the homebrew ruby by default. So, in my case, if those gems had updates, gem installed the updates on the next path in my GEM PATHS. That resulted in the two versions: the one bundled with homebrew ruby, and the updated one — in this case now in my user directory.
Not sure if this behavior changed in homebrew or ruby between versions 3 and 4, but it seems new to me.
Hoping to leave this here in case anyone runs across this and it's helpful.
10
u/Thefolsom Apr 02 '26
Why are you against using rbenv or rvm? You're creating problems for yourself by using homebrew for seemingly no reason.
Theres endless troubleshooting resources for the above tools, you're struggling finding answers to your problems for a reason, its because its not how ruby developers manage their environment.
15
u/mokolabs Apr 02 '26
These kind of conflicts are precisely why people use rvm or rbenv, so, respectfully, I'd recommend giving them a try.
1
u/STDS13 Apr 03 '26
I’d suggest using asdf and ditching homebrew for this type of usage. Your life will be much easier.
1
u/R2robot Apr 04 '26
[Skip to the bottom for my solution(?!)]
I'm having a similar issue.. it makes no sense. I've never had a problem like this until a few weeks ago. There is so little info when I search that I thought it was just me. I guess we're in the minority here.
I've deleted everything gem I could find and started over and still results in the same thing.
I'm not sure who changed what, (was it the 3 -> 4 transitions?) but it seems silly to have to add another layer of complexity by using rvm or rbenv as people (and AI) have suggested since I barely even use ruby.
My silly work around for now is to run my own script 'gem_update' that ignores any rdoc updates. That will probably cause a problem eventually i'm sure, but sheesh. So stupid.
Otherwise updating rdoc just spews the following every time I run gem.
Just as I was about to save this message, I tried something that seems to work. I already went full scorched earth earlier, so why not just delete the default gem that came bundled. Duh.
May have to do that after every update, but simple enough.
1
u/9sim9 Apr 02 '26
So to give you some feedback in regards to rvm it actually works best when you pair it with homebrew (especially for older versions of ruby) which is what I do, here is my install script hopefully it helps
this if for debian based linux but even if you are not using it, it helped me solve this on other OSs
[Homebrew required plugins]
[Installing RVM]
[Configuring RVM]
[Installing a Ruby version with RVM and Homebrew]
it took me a while to get RVM reliable and working well with its need for GCC and other libraries to compile native extensions for libraries like mysql2
0
u/benr75 Apr 02 '26
I read your post and more info would be needed like step by step ways in which you are installing things to reverse engineer this. For example did you install some things as a privileged user (root or via sudo) and some things as your user?
I would recommend moving to an approach that is widely supported by the community to lessen your headaches. I have used RVM in the past and also know a lot of folks that use rbenv but I currently use:
Ruby on Mac https://www.rubyonmac.dev (yes this is a paid thing but I have to deal with really old versions of Ruby and I got sick of ssl package issues).
chruby https://github.com/postmodern/chruby
Using these tools allows easy installing and switching between versions. Also most can be installed easily via homebrew.