Tutorial

[Fix] Build Failed while Installing Ruby with Rbenv on M1 Mac

Pinterest LinkedIn Tumblr

Error Message

Let’s reproduce the error first:

  1. Install Ruby with Rbenv
     $ rbenv install 2.7.2

    NOTE: In my M1 Mac, I tried installing various ruby versions with Rbenv like 2.5.0, 2.6.0, 2.7.0, 2.7.1, 2.7.2 and always ran into this same issue.

  2. Install error

You will get the following error message

  • BUILD FAILED (macOS 11.2.3 using ruby-build 20210309)
  • Inspect or clean up the working tree at /var/folders/.....

Screenshot of ruby installation error message
Error Message

Fix

Instead of running the normal ruby install command with rbenv, let’s prepend it with RUBY_CFLAGS="-Wno-error=implicit-function-declaration", which will suppress all errors and warnings and let the ruby installation complete.

$ RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.0

Conclusion

Tada! See the magic? Ruby should install without any issue now.

Are you using any other method to fix the issue? Let us know in the comments below.

Thank you for reading!

References

Freelancing Software Developer | Ruby on Rails, Reactjs, React Native, Gatsby, Saas, Bootstrap | Traveller | Spiritual Practitioner

1 Comment

  1. Hello, I’m new to the M1 Mac mini, I have no trouble in installing ruby. I have already installed ruby 2.7.3 with rbenv, but when I try to use ‘bundle install’ to install dependencies in my program, it failed while installing mysql2 (0.5.3). I tried `gem install mysql2 -v ‘0.5.3’ –source ‘https://rubygems.org/’ and it failed with code:
    ‘linking shared-object mysql2/mysql2.bundle
    ld: library not found for -lzstd
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [mysql2.bundle] Error 1’.
    So how Can I fix this ?

Write A Comment