How to install Ruby on Apple Sillicon M1/M2 architecture?
Follow these steps:
- Install
xcode
usingsudo xcodebuild -license agree
- Edit
~/.zshrc
, adding the followingexport
statements and aliases:
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"
export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
export PATH="/opt/homebrew/opt/sqlite/bin:$PATH"
alias abrew='/opt/homebrew/bin/brew'
alias ibrew='arch -x86_64 /usr/local/bin/brew'
- Run
source ~/.zshrc
to apply changes. - Install required dependencies using
abrew install openssl libffi zlib rbenv readline ruby-build
- Install Ruby using
RUBY_CONFIGURE_OPTS=--with-readline-dir="$(abrew --prefix readline)" rbenv install x.y.z
- If it does not work, try using
LDFLAGS="-L/opt/homebrew/opt/libffi/lib" CPPFLAGS="-I/opt/homebrew/opt/libffi/include" RUBY_CONFIGURE_OPTS=--with-readline-dir="$(abrew --prefix readline)" rbenv install x.y.z
Credit for the solution goes to @otavioschwanck - thank you!
How to install gem mysql2
on Apple Sillicon M1/M2 architecture?
In your CLI, run the following commands:
brew install mysql
brew install openssl@3
bundle config build.mysql2 \
--with-mysql-lib=$(brew --prefix mysql)/lib \
--with-mysql-dir=$(brew --prefix mysql)\
--with-mysql-config=$(brew --prefix mysql)/bin/mysql_config \
--with-mysql-include=$(brew --prefix mysql)/include\
--with-ldflags=-L/$(brew --prefix openssl@3)/lib\
--with-cppflags=-I/$(brew --prefix openssl@3)/include
gem install mysql2
Credit for the solution goes to @newx - thank you!
How to install gem pg
on Apple Sillicon M1/M2 architecture?
In your CLI, run the following commands:
brew install libpq
# add to .zshrc
export PATH="$(brew --prefix libpq)/bin:$PATH"
gem install pg
Credit for the solution goes to @wbharding - thank you!
How to install gem sqlite3
on Apple Sillicon M1/M2 architecture?
Follow these steps:
- Install
sqlite
on your system usingbrew install sqlite
- In your project, run
bundle add sqlite3
- If the installation fails, edit the
sqlite3
reference in yourGemfile
to include following installation flags:
gem "sqlite3", "~> x.y", platforms: [:ruby]
This also applies to running SQLite3 with Ruby in the alpine-based docker containers on Apple M1/M2 architecture.
Try hix.dev now
Simplify project configuration.
DRY during initialization.
Prevent the technical debt, easily.