Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing Ruby 2.5 on Mac M1

I was able to get Ruby 2.5.1 building on M1 by following two of the steps in that GH issue...

rbenv/ruby-build#1691 (comment) rbenv/ruby-build#1691 (comment)

I installed readline and openssl with standard brew install.

brew install readline
brew install openssl

Then I set this in my ~/.zshrc..

# Homebrew
export PATH=/opt/homebrew/bin:$PATH
export PATH="/opt/homebrew/sbin:$PATH"
# rbenv
export RBENV_ROOT=/opt/homebrew/opt/rbenv
export PATH=$RBENV_ROOT/bin:$PATH
eval "$(rbenv init -)"
# openssl
export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/openssl@1.1"

Then I ran this command:

RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5

I haven't been able to test this yet, but @samik3k has reported that this no longer works, but that the following command does.

RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.5.8

Please reply and let me know if this works for you and I'll update the steps above as I don't have Ruby setup on my M1 Mac right now.

@klaygomes
Copy link

If you are using rvm you can also resolve the same problem running:
CPPFLAGS=$CPPFLAGS"-Wno-error=implicit-function-declaration -Wno-error=compound-token-split-by-macro" rvm install 2.5.9

@katzenbaer
Copy link

Thanks @klaygomes that worked for me!

@gregmatthewcrossley
Copy link

Note that you'll need to keep all the new stuff in .zshrc above. I thought I could just delete it all after I sucesfully installed this Ruby version, but the RBENV_ROOT definition is apparently neccesary (I was getting rbenv: version 2.5.0 is not installed errors when running any gem commands).

@jonathancsr
Copy link

Thanks @MarkBennett that worked for me!

@MarkBennett
Copy link
Author

Glad this is working for people! 🎉

@ba11b0y
Copy link

ba11b0y commented Feb 4, 2022

Thanks @klaygomes
Works like a charm!

@rubyonrails3
Copy link

@klaygomes awesome it worked!

@frostmark
Copy link

Thank you! It helped to me

@zaheeraws
Copy link

zaheeraws commented May 13, 2022

Just this command worked for me:

RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.5

@whatcould
Copy link

@zaheeraws that worked for me for 2.5.3, thanks! The flags above still gave me an error.

@unixsuperhero
Copy link

worked for 2.5.8, on an m1 max mac studio

@gentax
Copy link

gentax commented Jul 19, 2022

worked for 2.5.3 on my macbook air M1.
Good catch!

@dankild
Copy link

dankild commented Jul 27, 2022

Thank you! Worked well on MBP 14 for Ruby 2.5.8!

@jraczynski
Copy link

Also helped me, thanks! M1, Ruby 2.5.9.

@danielricecodes
Copy link

You should use brew install openssl@1.1 since homebrew now install openssl 3 by default.

@samik3k
Copy link

samik3k commented Nov 26, 2022

Not working anymore, rbent and rvm variant, compilation error. Anyone know how to fix it on macos 13.0.1?

@samik3k
Copy link

samik3k commented Nov 26, 2022

Working RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.5.8

@fabianof
Copy link

Working RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.5.8

It worked like a charm. Thanks a lot.

@emskaplann
Copy link

Working RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.5.8

worked for m2 - thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment