Skip to content

Instantly share code, notes, and snippets.

@CaiqueMitsuoka
Last active November 15, 2023 08:11
Show Gist options
  • Save CaiqueMitsuoka/e428fca199bc6e9bf5bd8b1ec217136f to your computer and use it in GitHub Desktop.
Save CaiqueMitsuoka/e428fca199bc6e9bf5bd8b1ec217136f to your computer and use it in GitHub Desktop.
Install old ruby version on M1
# Rbenv thread for old versions after xcode 12+
# https://github.com/rbenv/ruby-build/issues/1489
# PR for openssl 1.0 to support M1
# https://github.com/rbenv/homebrew-tap/pull/2
curl https://raw.githubusercontent.com/rbenv/homebrew-tap/e472b7861b49cc082d1db0f66f265368da107589/Formula/openssl%401.0.rb -o ./openssl@1.0.rb
brew install openssl@1.0.rb
brew --prefix openssl@1.0
brew --prefix readline
# Worked
LDFLAGS="" CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/openssl@1.0" asdf install ruby 2.3.8
## UPDATE
# Things changed since, basically the following update is for Mac Sonoma 14 something
# rbenv is our only savior
brew install zlib readline libyaml libffi ruby-build rbenv
export RUBY_CONFIGURE_OPTS="--with-zlib-dir=$(brew --prefix zlib) --with-openssl-dir=$(brew --prefix openssl@1.1) --with-readline-dir=$(brew --prefix readline) --with-libyaml-dir=$(brew --prefix libyaml) --with-gdbm-dir=$(brew --prefix gdbm)"
# This was not necessary but try it if you are still getting errors, and it might be nedded for especific gems
# export CFLAGS="-Wno-error=implicit-function-declaration"
RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.7.0
# To actually run Rails you need this variable
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
bin/rails s
# For pg gem try this
brew install libpq
export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
gem install pg -v '0.18.4' --source 'https://rubygems.org/' -- --with-pg-config=/opt/homebrew/Cellar/libpq/16.0/bin/pg_config --with-cflags="-Wno-error=implicit-function-declaration"
LDFLAGS="-L/opt/homebrew/opt/libffi/lib" CPPFLAGS="-I/opt/homebrew/opt/libffi/include" gem install ffi -v '1.9.23' -- --with-cflags="-Wno-error=implicit-function-declaration" --enable-system-libffi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment