DEV Community

Cover image for Install 2.x, 3.x version of Ruby via rbenv on M1 Mac
Yasuhiro Nagata
Yasuhiro Nagata

Posted on

7 2

Install 2.x, 3.x version of Ruby via rbenv on M1 Mac

I bought new M1 Mac and struggled to install Ruby.

Here’s what I did to solve the issue.

This solution worked for me installing Ruby 2.6.6 and 3.0.2.

  1. Installed anyenv via brew

    brew install anyenv
    
  2. Installed rbenv via anyenv

    anyenv install rbenv
    
  3. Then I got an error while installing Ruby rbenv install 2.6.6

    rbenv install 2.6.6
    Downloading openssl-1.1.1q.tar.gz...
    -> https://dqw8nmjcqpjn7.cloudfront.net/d7939ce614029cdff0b6c20f0e2e5703158a489a72b2507b8bd51bf8c8fd10ca
    Installing openssl-1.1.1q...
    
    BUILD FAILED (macOS 12.3 using ruby-build 20220630-3-g2155888)
    
    Inspect or clean up the working tree at /var/folders/7w/__wt6xg10rv3jdq_z2rjt8300000gn/T/ruby-build.20220706155948.38261.B1lwKj
    Results logged to /var/folders/7w/__wt6xg10rv3jdq_z2rjt8300000gn/T/ruby-build.20220706155948.38261.log
    
    Last 10 log lines:
    clang  -Iinclude -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DZLIB_SHARED -DNDEBUG -I/Users/yas/.anyenv/envs/rbenv/versions/2.6.6/include  -MMD -MF test/wpackettest.d.tmp -MT test/wpackettest.o -c -o test/wpackettest.o test/wpackettest.c
    clang  -Iinclude -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DZLIB_SHARED -DNDEBUG -I/Users/yas/.anyenv/envs/rbenv/versions/2.6.6/include  -MMD -MF test/x509_check_cert_pkey_test.d.tmp -MT test/x509_check_cert_pkey_test.o -c -o test/x509_check_cert_pkey_test.o test/x509_check_cert_pkey_test.c
    test/v3ext.c:201:24: error: implicitly declaring library function 'memcmp' with type 'int (const void *, const void *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
            if (!TEST_true(memcmp(ip1->data, ip2->data, ip1->length) <= 0))
                           ^
    test/v3ext.c:201:24: note: include the header <string.h> or explicitly provide a declaration for 'memcmp'
    1 error generated.
    make[1]: *** [test/v3ext.o] Error 1
    make[1]: *** Waiting for unfinished jobs....
    make: *** [all] Error 2
    
  4. This error is related to Openssl

    1. His post was so helpful.
      https://github.com/rbenv/ruby-build/discussions/1853#discussioncomment-2146106

      Fundamentally speaking, it is caused by OpenSSL.
      OpenSSL@3.0 came in Sep 2021, but it was not compatible with ruby-build. So we have to switch the OpenSSL@1.1.

  5. Installed openssl version 1.1 using brew

    brew install openssl@1.1
    
  6. Then set PATH to openssl@1.1

    yas@MBP2 ~> which openssl
    /usr/bin/openssl
    yas@MBP2 ~> fish_add_path /opt/homebrew/opt/openssl@1.1/bin // set PATH. this is for fish shell.
    // if you use other than fish, add '/opt/homebrew/opt/openssl@1.1/bin' to your PATH.
    yas@MBP2 ~> exec $SHELL -l //refresh shell
    yas@MBP2 ~> which openssl
    /opt/homebrew/opt/openssl@1.1/bin/openssl
    
  7. Install Ruby using a prefix

    CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.6
    

Hope this helps

Hot sauce if you're wrong - web dev trivia for staff engineers

Hot sauce if you're wrong · web dev trivia for staff engineers (Chris vs Jeremy, Leet Heat S1.E4)

  • Shipping Fast: Test your knowledge of deployment strategies and techniques
  • Authentication: Prove you know your OAuth from your JWT
  • CSS: Demonstrate your styling expertise under pressure
  • Acronyms: Decode the alphabet soup of web development
  • Accessibility: Show your commitment to building for everyone

Contestants must answer rapid-fire questions across the full stack of modern web development. Get it right, earn points. Get it wrong? The spice level goes up!

Watch Video 🌶️🔥

Top comments (9)

Collapse
 
ryan_dowler_9e3cc081f0251 profile image
Ryan Dowler

I just created an account to Thank You!! :)

Collapse
 
yasuhiron777 profile image
Yasuhiro Nagata • Edited

Thank you Ryan! I'm happy that I could help you!

Collapse
 
tomus11 profile image
Tom Lane

I'm lost trying to install ruby versions using rbenv. Might you have a bit of time to help me troubleshoot? I've tried what's here but am experiencing a different set of issues related to the clang compiler

Collapse
 
tnir profile image
T "@tnir" N

Why not 2.7? 2.6 got EOL'd early this year.

Collapse
 
yasuhiron777 profile image
Yasuhiro Nagata

Thanks for telling!
My company product is running on 2.6 now, so I had no choice :-(

Collapse
 
tnir profile image
T "@tnir" N

🤔 Use 2.7 or higher very soon in your company!

Thread Thread
 
yasuhiron777 profile image
Yasuhiro Nagata

Got it! I'm gonna suggest it to my team.😊

Collapse
 
sahsu profile image
Sean Hsu

That's also what I doing for replace my M1 macbook air from INTEL to Apple base, thanks!

Collapse
 
yasuhiron777 profile image
Yasuhiro Nagata

Good to know!
Thanks for your feedback!

Image of Quadratic

Python + AI + Spreadsheet

Chat with your data and get insights in seconds with the all-in-one spreadsheet that connects to your data, supports code natively, and has built-in AI.

Try Quadratic free

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay