Skip to content

Instantly share code, notes, and snippets.

@andritcharthur
Last active March 16, 2022 02:25
Show Gist options
  • Select an option

  • Save andritcharthur/39fd08805edf83f03ad3c85c926ae042 to your computer and use it in GitHub Desktop.

Select an option

Save andritcharthur/39fd08805edf83f03ad3c85c926ae042 to your computer and use it in GitHub Desktop.
Instructions for installing older version of Ruby (2.2.0) on Mac M1
Step 0: Cleanup any brew installations to clear things up
brew cleanup
Step 1: Install this dependency you'll need later on
brew install makedepend
Step 2: download openssl@1.0.rb file and save it your User folder
https://gist.githubusercontent.com/andritcharthur/be5c0d334f6817942087f7d36de0dd0c/raw/4d9d6401885da5eb296d818ec003c864b25ce3e4/openssl@1.0.rb
Step 3: Install the older openssl using brew. (have to run command from inside your user folder or wherever the file is)
brew install ./openssl@1.0.rb
Step 4: Add these lines to your .zshrc file (~/.zshrc)
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH="/opt/homebrew/opt/openssl@1.0/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.0/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.0/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.0/lib/pkgconfig"
export RUBY_CFLAGS="-DUSE_FFI_CLOSURE_ALLOC -Wno-error=implicit-function-declaration"
export optflags="-w"
export RUBY_CONFIGURE_OPTS=--with-openssl-dir=/opt/homebrew/opt/openssl@1.0 rbenv install
Step 5: Restart your terminal
Step 6: Double check the Openssl version
openssl version
Should be -> "OpenSSL 1.0.2u 20 Dec 2019"
Step 7: Install ruby 2.2.0! It takes a while
CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS='--with-readline-dir=/usr/local/opt/readline/' arch -x86_64 rbenv install 2.2.0
Step 8: Double check the Ruby version
ruby -v
Should be -> "ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin21]"
Step 9: Install the right bundler version
gem install bundler -v '1.8.4'
Step 10: Restart Terminal again
Step 10: Double check the version of bundler
bundle -v
Should be "Bundler version 1.8.4"
Step 11: In the project, change the URL from 'https://.rails-assets.org' to --> 'http://insecure.rails-assets.org'
/<project folder>/Gemfile Line #73
Step 12: Install nokogiri with options compatible with M1 Mac
gem install nokogiri -v '1.6.6.4' -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries
gem install byebug
Step 12: Run Bundler from inside project folder to install dependencies
bundle install
Step 13: Run npm install to install dependencies
npm i
Step 14: There might be more steps but I stopped here. You should be able to take it from here.
References:
https://github.com/rbenv/ruby-build/issues/1700
http://grantcss.com/blog/2021/10/27/install-ruby-2-dot-2-m1-pro/
https://github.com/rbenv/ruby-build/issues/1691#issuecomment-753636901
https://github.com/rbenv/homebrew-tap/pull/2
https://gist.github.com/felixbuenemann/5f4dcb30ebb3b86e1302e2ec305bac89
https://github.com/rbenv/ruby-build/issues/1742#issuecomment-835790760
@loso-nd
Copy link

loso-nd commented Mar 7, 2022

If you need to have openssl@1.0 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openssl@1.0/bin:$PATH"' >> ~/.zshrc

Order of this path file matters

@loso-nd
Copy link

loso-nd commented Mar 7, 2022

After Step 11:
$ gem install nokogiri:1.6.6.2 -- --use-system-libraries

Gemfile replace the following:
gem 'byebug', '9.1.0'
gem 'pg', '~> 0.15'
source 'http://insecure.rails-assets.org'

Permission issue with pg - >

check chmod -R +w ~/.rbenv ( shows the permissions and owner)
chown -R user:group ~/.rbenv ( chnages the permissions and owner)

$ brew install libpq

$ brew install postgressql

@loso-nd
Copy link

loso-nd commented Mar 16, 2022

Trouble shooting command:
brew list postgresql
which pg_config
which psql
cd /opt/homebrew/bin/psql
commands with usr wil not workin in Mac M1

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