I'm trying to run a Ruby project on my M1 Mac. However, I'm running into the following error when running gem
in my command line:
<internal:/Users/matti/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require': dlopen(/Users/matti/.rvm/gems/ruby-3.1.2/gems/strscan-3.0.3/lib/strscan.bundle, 0x0009): tried: '/Users/matti/.rvm/gems/ruby-3.1.2/gems/strscan-3.0.3/lib/strscan.bundle' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))) - /Users/matti/.rvm/gems/ruby-3.1.2/gems/strscan-3.0.3/lib/strscan.bundle (LoadError)
After looking around to different StackOverflow posts regarding this error, I wasn't able to find a post dealing with gem
not working. Any attempt to run gem uninstall
or gem -arch -arm64e
were not working, was getting the same error above.
Ruby version:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
I believe the root cause of this error was because I initially tried installing the Gems on an Intel-based version of RubyMine on my M1 Mac. I think this tried to install the Intel dependencies, until it eventually hit an error due to architecture compatibility.
To resolve this issue, I removed the ruby-3.1.2 directory following /Users/matti/.rvm/rubies/
and then ran bundle install
. All my dependencies installed successfully.