DEV Community

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

Posted on

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

Discussion (8)

Collapse
ryan_dowler_9e3cc081f0251 profile image
Ryan Dowler

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

Collapse
yasuhiron777 profile image
Yasuhiro Nagata Author • Edited on

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

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 Author

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 Author

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 Author

Good to know!
Thanks for your feedback!