A Tale of OpenSSL and Persistence
Picture this: You’re excited to dive into Ruby on Rails 8 development on your shiny new M1/M2 Mac, but OpenSSL is giving you the cold shoulder. Don’t worry – you’re not alone in this dance! Let’s turn that frustration into a success story with this comprehensive guide.
The Challenge
If you’ve tried installing Ruby 3.4.1 on your Apple Silicon Mac and encountered OpenSSL-related errors, you might have seen something like:
Error running '__rvm_make -j8',
please read /Users/username/.rvm/log/ruby-3.4.1/make.log
Or perhaps the dreaded:
OpenSSL is not available. Install OpenSSL and rebuild Ruby
The Solution: A Fresh Start Approach
Sometimes the best way forward is to start fresh. Here’s our battle plan:
1. Clean House: Remove Old Version Managers
First, let’s remove any existing Ruby version managers. They’re like having multiple GPS systems giving you different directions – not helpful!
# If you have RVM installed
rvm implode
# If you have rbenv installed
rm -rf ~/.rbenv
# Clean up any remaining pieces
sudo rm -rf /usr/local/lib/ruby
sudo rm -rf /usr/local/bin/ruby
sudo rm -rf /usr/local/share/ruby
rm -rf ~/.gem
2. Install Homebrew in the Correct Location
On Apple Silicon Macs, Homebrew needs to live in /opt/homebrew, not /usr/local:
# Uninstall existing Homebrew (if it's in the wrong location)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
# Install Homebrew fresh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to your PATH
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
eval "$(/opt/homebrew/bin/brew shellenv)"
3. Install ASDF Version Manager
ASDF is like a Swiss Army knife for version management – it handles multiple languages beautifully:
# Install ASDF
brew install asdf
# Add ASDF to your shell
echo "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.zshrc
source ~/.zshrc
4. Configure OpenSSL
Now for the secret sauce – proper OpenSSL configuration:
# Install OpenSSL@3
brew install openssl@3
# Set up environment variables
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/readline/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/readline/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig:/opt/homebrew/opt/readline/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/openssl@3 --enable-shared"
5. Install Ruby and Rails
With our foundation solid, let’s install Ruby and Rails:
# Install Ruby plugin for ASDF
asdf plugin add ruby
# Install Ruby 3.4.1
asdf install ruby 3.4.1
# Set it as your global Ruby version
asdf global ruby 3.4.1
# Verify installation
ruby -v # Should show 3.4.1 with PRISM
Now for Rails:
# Install Rails 8.0.1
gem install rails -v 8.0.1
# Verify installation
rails -v # Should show 8.0.1
6. Create Your First Rails 8 API
Let’s test our setup with a new Rails API project:
# Create a new API-only Rails application
rails new my_api_app --api
Bonus: Shell Configuration
Here’s a clean, organized .zshrc configuration that ties everything together:
# ASDF Setup
. /opt/homebrew/opt/asdf/libexec/asdf.sh
# Ruby/Rails Configuration
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/readline/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/readline/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig:/opt/homebrew/opt/readline/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/openssl@3 --enable-shared"
# Auto-set Ruby version on terminal launch
. /opt/homebrew/opt/asdf/libexec/asdf.sh && asdf local ruby 3.4.1
Troubleshooting Tips
- Getting permission errors? Try running
sudo chown -R $(whoami) ~/.asdf - Rails command not found? Run
asdf reshim ruby - Still seeing old Ruby versions? Check your PATH with
echo $PATH | tr ':' '\n'and remove any duplicate entries
Conclusion
Setting up Ruby and Rails on Apple Silicon might feel like solving a puzzle blindfolded, but with the right approach, it’s totally manageable. The key is starting fresh and ensuring everything is properly configured for the M1/M2 architecture.
Remember: A clean development environment is like a well-organized kitchen – everything has its place, and cooking (or coding) becomes a joy rather than a chore!
Additional Resources
Last updated: January 2024





0 Comments