Getting "Failed to build gem native extension" Error After Upgrading to Mac OS Big Sur
Problem
After upgrading to Mac OS Big Sur, I saw this error I haven’t seen before:
➜ bundle exec jekyll serve
Could not find commonmarker-0.17.13 in any of the sources
Run `bundle install` to install missing gems.
So I ran bundle install
but it didn’t seem to work either. An excerpt from the terminal output:
➜ bundle install
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
An error occurred while installing commonmarker (0.17.13), and Bundler cannot continue.
Make sure that `gem install commonmarker -v '0.17.13' --source 'https://rubygems.org/'` succeeds before bundling.
An error occurred while installing unf_ext (0.0.7.7), and Bundler cannot continue.
Make sure that `gem install unf_ext -v '0.0.7.7' --source 'https://rubygems.org/'` succeeds before bundling.
An error occurred while installing rdiscount (2.2.0.2), and Bundler cannot continue.
Make sure that `gem install rdiscount -v '2.2.0.2' --source 'https://rubygems.org/'` succeeds before bundling.
Solution
After some research and trial and error, I found this precious answer in Stack Overflow that it is due to the Ruby version that is not compatible with Big Sur and it should be at least 2.7. So I checked Ruby releases and decided to go with one of the most recent releases: 2.7.2.
Anyway, steps I think worked:
- Check Ruby version
➜ ruby -v ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
- Install Ruby Version Manager (rvm)
➜ curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s stable
- Install 2.7.2 version using rvm
➜ rvm install "ruby-2.7.2"
- Check Ruby version again
➜ ruby -v ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
- Bundle install
➜ bundle install
- Run bundle
➜ bundle exec jekyll serve
And it worked!
Some other things I tried
-
Installing Ruby through Homebrew: didn’t solve the issue but I don’t know if this actually and eventually helped or not.
➜ brew install ruby
-
Installing the latest version of Ruby (ref) using rvm: didn’t update the version for some reason.
➜ rvm install ruby@latest