Skip to content

Instantly share code, notes, and snippets.

@metacritical
Created November 2, 2025 05:54
Show Gist options
  • Select an option

  • Save metacritical/3a853c2166c2790a62c1dad9860d51a2 to your computer and use it in GitHub Desktop.

Select an option

Save metacritical/3a853c2166c2790a62c1dad9860d51a2 to your computer and use it in GitHub Desktop.
Ruby 3.4.7 Install Guide
#!/bin/bash
# Script to install Ruby 3.4.7 on macOS ARM64 (M1/M2)
# This script handles the known compilation issues with Ruby 3.4.7 on Apple Silicon
set -e # Exit on any error
echo "Installing Ruby 3.4.7 on macOS ARM64"
echo "==================================="
# Check if running on ARM64 (Apple Silicon)
if [[ "$(uname -m)" != "arm64" ]]; then
echo "Warning: This script is designed for macOS ARM64 (M1/M2). You are running on $(uname -m)"
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Check if Homebrew is installed
if ! command -v brew &> /dev/null; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH for this session
if [[ -d "/opt/homebrew/bin" ]]; then
export PATH="/opt/homebrew/bin:$PATH"
elif [[ -d "/usr/local/bin" ]]; then
export PATH="/usr/local/bin:$PATH"
fi
else
echo "Homebrew is already installed"
fi
# Update Homebrew
echo "Updating Homebrew..."
brew update
brew upgrade
# Install required dependencies
echo "Installing dependencies..."
brew install openssl readline libyaml gmp
# Install rbenv if not already installed
if ! command -v rbenv &> /dev/null; then
echo "Installing rbenv..."
brew install rbenv ruby-build
else
echo "rbenv is already installed"
# Ensure ruby-build is installed
if ! brew list ruby-build &>/dev/null; then
brew install ruby-build
fi
fi
# Add rbenv to shell profile if not already there
SHELL_PROFILE="$HOME/.zshrc"
if [[ "$SHELL" == *"bash"* ]]; then
SHELL_PROFILE="$HOME/.bash_profile"
fi
if ! grep -q "rbenv init" "$SHELL_PROFILE"; then
echo 'eval "$(rbenv init -)"' >> "$SHELL_PROFILE"
fi
# Reload rbenv in current session
eval "$(rbenv init -)"
echo "Attempting to install Ruby 3.4.7..."
echo "This may take 10-20 minutes..."
# Try the standard installation first
if env LDFLAGS="-L/opt/homebrew/lib" CPPFLAGS="-I/opt/homebrew/include" \
rbenv install 3.4.7 --verbose 2>/dev/null; then
echo "✅ Ruby 3.4.7 installed successfully with standard method"
else
echo "❌ Standard installation failed, proceeding with manual build method..."
# Clean up any partial installation
rm -rf ~/.rbenv/sources/3.4.7 2>/dev/null || true
# Download and extract Ruby source
echo "Downloading Ruby 3.4.7 source code..."
cd /tmp
if [[ -d "ruby-3.4.7" ]]; then
rm -rf ruby-3.4.7
fi
curl -O https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.7.tar.gz
tar -xzf ruby-3.4.7.tar.gz
cd ruby-3.4.7
# Configure with ARM64-specific flags
echo "Configuring Ruby build..."
./configure --prefix="$HOME/.rbenv/versions/3.4.7" \
--with-coroutine=ucontext \
--disable-dtrace \
--disable-profiling \
--with-arch=arm64
# Apply patches to fix ARM64 build issues
echo "Applying patches for ARM64 build issues..."
# Patch mkconfig.rb to handle missing architecture information
sed -i.bak "s/arch = \$arch or raise \"missing -arch\"/arch = \$arch || ENV['arch'] || 'arm64-darwin25'/" tool/mkconfig.rb
sed -i.bak2 "s/version = \$version or raise \"missing -version\"/version = \$version || ENV['version'] || '3.4.7'/" tool/mkconfig.rb
# Start build process
echo "Building Ruby 3.4.7 (this will take 10-15 minutes)..."
make -j$(sysctl -n hw.ncpu || nproc)
# Install the built Ruby
echo "Installing Ruby 3.4.7..."
make install
# Add to rbenv so it's recognized
rbenv rehash
echo "✅ Ruby 3.4.7 installed successfully with manual method"
fi
# Set as default Ruby version if requested
echo "Ruby 3.4.7 has been installed!"
read -p "Would you like to set Ruby 3.4.7 as your default Ruby version? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rbenv global 3.4.7
echo "Ruby 3.4.7 is now your default Ruby version"
fi
# Verify installation
echo "Verifying installation..."
ruby_version=$(ruby -v 2>/dev/null || rbenv exec ruby -v)
echo "Ruby version: $ruby_version"
# Test basic functionality
if rbenv exec ruby -e "puts 'Ruby installation test successful!'" &>/dev/null; then
echo "✅ Ruby is working correctly"
else
echo "❌ Ruby installation may have issues"
exit 1
fi
echo
echo "Installation complete!"
echo "- Ruby 3.4.7 is installed at ~/.rbenv/versions/3.4.7"
echo "- To use Ruby 3.4.7: rbenv local 3.4.7 or rbenv global 3.4.7"
echo
echo "Note: Ruby 3.4.7 may have compatibility issues with the concurrent-ruby gem"
echo "causing segmentation faults in some applications."
echo "This only affects runtime with specific gems, not the installation itself."

Installing Ruby 3.4.7 on macOS ARM64 (M1/M2)

This guide details the steps needed to successfully install Ruby 3.4.7 on Apple Silicon Macs (M1/M2), which has some known compatibility issues during compilation.

Prerequisites

First, ensure your system is ready:

# Update Homebrew
brew update && brew upgrade

# Install build dependencies
brew install openssl readline libyaml gmp

Method 1: Using rbenv (Recommended)

  1. Update environment variables to use symlinked paths for resilience:
# Add these to your ~/.bash_profile, ~/.zshrc, or appropriate shell config
export LDFLAGS="-L/opt/homebrew/opt/openblas/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openblas/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openblas/lib/pkgconfig:$PKG_CONFIG_PATH"
  1. Install rbenv and ruby-build if not already installed:
brew install rbenv ruby-build
  1. Install Ruby 3.4.7 with specific configuration:
# Configure with proper flags to handle ARM64 build issues
env LDFLAGS="-L/opt/homebrew/lib" CPPFLAGS="-I/opt/homebrew/include" \
    rbenv install 3.4.7 --verbose

Method 2: Manual Build (When rbenv fails)

If the rbenv installation still fails, you'll need to build from source with patches:

  1. Download Ruby 3.4.7 source:
cd /tmp
curl -O https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.7.tar.gz
tar -xzf ruby-3.4.7.tar.gz
cd ruby-3.4.7
  1. Configure and patch build scripts:
./configure --prefix=/Users/$(whoami)/.rbenv/versions/3.4.7 \
    --with-coroutine=ucontext \
    --disable-dtrace \
    --disable-profiling
  1. Apply patches to mkconfig.rb due to ARM64-specific build issues:
# Patch the script to handle missing architecture information
sed -i.bak "s/arch = \$arch or raise \"missing -arch\"/arch = \$arch || ENV['arch'] || 'arm64-darwin25'/" tool/mkconfig.rb
sed -i.bak2 "s/version = \$version or raise \"missing -version\"/version = \$version || ENV['version'] || '3.4.7'/" tool/mkconfig.rb
  1. Build and install:
make -j$(nproc || sysctl -n hw.ncpu)
make install
  1. Refresh rbenv:
rbenv rehash
rbenv install 3.4.7 --verbose  # To register the manually installed version

Troubleshooting Common Issues

Issue: "missing -arch" error

  • Cause: Ruby build script can't determine architecture on ARM64
  • Solution: Apply patches to mkconfig.rb as shown above

Issue: OpenBLAS LDFLAGS conflicts

  • Cause: Environment variables point to old OpenBLAS version
  • Solution: Use symlinked paths (/opt/homebrew/opt/openblas/lib) instead of versioned paths

Issue: Segmentation fault with concurrent-ruby

  • Cause: Known issue with Ruby 3.4.7 on ARM64 with certain gems
  • Solution: This affects runtime with gems like concurrent-ruby, but installation is successful

Verification

After installation:

# Check Ruby version
rbenv global 3.4.7
ruby -v

# Test basic functionality
ruby -e "puts 'Ruby 3.4.7 installed successfully!'"

Notes

  • Ruby 3.4.7 builds successfully on ARM64 but has known compatibility issues with the concurrent-ruby gem causing segmentation faults in some applications
  • The build process patches internal Ruby build scripts to fix ARM64-specific issues
  • Using symlinked paths in environment variables ensures resilience to Homebrew package updates
  • For production use, consider Ruby 3.4.1 which is functionally very similar and more stable on ARM64

Ruby 3.4.7 Installation Techniques for macOS ARM64

This document summarizes the key techniques used to successfully install Ruby 3.4.7 on macOS ARM64 (M1/M2) systems.

Core Issues Addressed

  1. OpenBLAS LDFLAGS Conflict: Build process picking up old or conflicting OpenBLAS paths
  2. "missing -arch" Error: Ruby's build script failing to determine ARM64 architecture
  3. "missing -version" Error: Similar issue with version detection
  4. ucontext deprecation warnings: macOS ARM64 deprecated some coroutine functions

Key Techniques Used

1. Environment Variable Configuration

  • Use symlinked paths instead of versioned paths: /opt/homebrew/opt/openblas/lib vs /opt/homebrew/Cellar/openblas/X.X.X/lib
  • Properly set LDFLAGS and CPPFLAGS to avoid OpenBLAS conflicts
  • Update shell profiles to use resilient paths for future updates

2. Build Configuration Patches

  • File: tool/mkconfig.rb
  • Issue: Architecture information not found during build
  • Solution: Patch arch = $arch or raise "missing -arch" to arch = $arch || ENV['arch'] || 'arm64-darwin25'
  • Issue: Version information not found during build
  • Solution: Patch version = $version or raise "missing -version" to version = $version || ENV['version'] || '3.4.7'

3. Configure Options for ARM64

  • Use --with-coroutine=ucontext for ARM64 compatibility
  • Use --disable-dtrace --disable-profiling to avoid build complications
  • Ensure proper architecture detection with --with-arch=arm64

4. Manual Build Process

  1. Download source code from Ruby's official repository
  2. Apply patches to build scripts before compilation
  3. Use make -j$(nproc || sysctl -n hw.ncpu) for parallel compilation
  4. Install to rbenv versions directory for integration

5. Environment Resilience

  • Update shell config files to use symlinked paths (/opt/homebrew/opt/) instead of versioned paths (/opt/homebrew/Cellar/X.X.X/)
  • This ensures environment remains valid across Homebrew updates
  • Helps prevent future build issues from outdated path references

Commands Used

For rbenv Method:

env LDFLAGS="-L/opt/homebrew/lib" CPPFLAGS="-I/opt/homebrew/include" rbenv install 3.4.7

For Manual Build:

# Patch build script
sed -i.bak "s/arch = \$arch or raise \"missing -arch\"/arch = \$arch || ENV['arch'] || 'arm64-darwin25'/" tool/mkconfig.rb
sed -i.bak2 "s/version = \$version or raise \"missing -version\"/version = \$version || ENV['version'] || '3.4.7'/" tool/mkconfig.rb

# Configure and build
./configure --prefix=/Users/$(whoami)/.rbenv/versions/3.4.7 --with-coroutine=ucontext --disable-dtrace --disable-profiling
make -j$(nproc || sysctl -n hw.ncpu)
make install

Important Notes

  • Ruby 3.4.7 compiles and installs successfully using these techniques
  • There's a known issue with the concurrent-ruby gem causing segmentation faults on ARM64
  • For production use with gems that depend on concurrent-ruby, consider using Ruby 3.4.1 instead
  • The installation techniques work around ARM64-specific build system incompatibilities
  • The patches to mkconfig.rb are temporary fixes for Ruby's build system on macOS ARM64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment