bundler config surprises
Initial symptom
I was working on getting an OSS Ruby project up and running, to poke around, run the test suite, and check out their open issues. I ran into an issue with installing its dependencies when running bundle install
:
Could not find gems matching 'sorbet-static (= 0.5.11481)' valid for all resolution
platforms (arm64-darwin, x86_64-darwin, x86_64-linux, ruby) in rubygems repository
https://rubygems.org/ or installed locally.
The source contains the following gems matching 'sorbet-static (= 0.5.11481)':
* sorbet-static-0.5.11481-aarch64-linux
* sorbet-static-0.5.11481-java
* sorbet-static-0.5.11481-universal-darwin
* sorbet-static-0.5.11481-x86_64-linux
I was doing this on an m1 Mac. I would’ve expected the “-universal-darwin” platform to work for mine (Darwin is the code name for macOS). So I assumed something was wrong with my setup, and set out to figure out what that was.
Things I tried
- Changing my Ruby version (using
asdf
) to the latest.- I use
asdf
, which is my 3rd Ruby version manager (after having triedrvm
andrbenv
). I’m generally very happy with it. It’s simple, it supports many tools (Ruby, node, Python, etc). And most of the time it just works and stays out of the way. That also means when I need to do something with it, I may have forgotten the incantations. - Relevant commands I used this time around.
asdf list all ruby 3
- While debugging this, I just learned you can pass a version after the plugin name, to filter down the results list. This is a massive usability improvement. It’s pretty massive and unreadable otherwise.
- When I typed this, my
asdf
reported 3.1.2 as the latest. I knew this actually wasn’t the latest. Another problem to fix.
asdf update plugin ruby
- Things I tried that failed:
brew update asdf
(already up to date).
- Things I tried that failed:
asdf install ruby lastest
asdf global ruby latest
- (I actually discovered in writing this post that I didn’t do this step. So I thought I had tried out another Ruby version but I installed it and didn’t actually try building the project with it, whoops!)
- Was on 3.1.2, tried 3.3.4
- Didn’t hurt but didn’t help
- I use
Update the version of bundler i’m using
- I figured maybe this was buggy or outdated bundler behavior, or the project uses a feature that my current one doesn’t support
gem update bundler
- This updated, but didn’t fix the bug.
Google around for a snippet of the “Could not find gems matching” message above
- I left out specifics of the platform and gem name in my search. They seemed too specific to get matches for.
- To my surprise, I got matches that included
sorbet-static
(probably not matching version numbers though). - Among Github Issues I read, there was mention of running bundler with
force_ruby_platform
. This sounded vaguely familiar, but not something I did today or even within the last year. Checked the Bundler docs page for
bundle config
and tadaaa:Ignore the current machine’s platform and install only ruby platform gems. As a result, gems with native extensions will be compiled from source.
- I ran this on my personal laptop when doing some contracting work shortly after getting this mac. M1 hadn’t been out for long, and there were issues with the protobuf gem. I was also just in a “just get things working to get things done” mode and most likely running snippets off StackOverflow somewhat blindly. Do I regret doing that now? No. Sometimes you just have to get things done in a expedient manner. It didn’t create more problems for me until years later. It also gave me an opportunity today to learn about what I ran years ago.
After finally understanding this is a cached value, it was as simple as:
bundle config list
bundle config unset force_ruby_platform
bundle config list
- (To verify my intended change took effect.)
Takeaways:
- Isolated / clean coding environments are nice for avoiding issues like this one
- Maybe I should introduce periodic system purges / reinstallations from scratch
- Google for the error message I’m seeing (genericized)
- This seems somewhat obvious, but I can get trapped by thinking “Oh I think I have a likely suspicion of what is causing this.”
bundle config
caches some values globally. Check it periodically and be aware of what’s configured on the system.