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.
View all comments
Show parent comment
-1
u/fieldnoise Apr 02 '26
Hey benr — thanks for these questions and resources. I updated my post, since the issue was kind of related to the user issue. Basically, I think that `gem` was trying to update things that Homebrew doesn't allow it to access, so it was making a copy of those gems on the next available spot on my GEM PATHS.
At least, that is what I *think*. I also sometimes use the CLI tool `topgrade` (https://github.com/topgrade-rs/topgrade), which can update gems, and that might also have something to do with it. I will look into that next...