Segmentation Fault during rails assets:precompile on Apple Silicon (M3) with Ruby 3.3.0 in Docker (with Kamal) – Ruby

by
Maya Patel
concurrent-ruby propshaft ruby-on-rails

Quick Fix: Utilize the patch for Ruby version 3.3.1 by building Ruby yourself until the patch is officially released.

The Solutions:

Solution 1: Built Ruby from the Source

The segmentation fault issue was fixed in a Ruby patch, which is now part of Ruby 3.3.1. Until this version is released, you can build Ruby from the source to apply the patch.

Here’s a summary of the steps to build Ruby from the source:

  1. Install the necessary dependencies:

    • On Linux: sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libncurses5-dev libffi-dev libgdbm-dev
    • On macOS: brew install readline libffi
  2. Download the Ruby source code:

    wget https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz
    
  3. Extract the source code:

    tar -xzf ruby-3.3.0.tar.gz
    
  4. Apply the patch:

  5. Configure, build, and install Ruby:

    cd ruby-3.3.0
    ./configure --prefix=/opt/ruby-3.3.0
    make
    sudo make install
    
  6. Add the new Ruby to your $PATH:

    echo 'export PATH=/opt/ruby-3.3.0/bin:$PATH' >> ~/.bashrc
    source ~/.bashrc
    
  7. Rebuild the Docker image:

    • Repeat the steps in your Dockerfile that build the Ruby application. Make sure to use the new version of Ruby (ruby-3.3.0).

After completing these steps, the segmentation fault issue should be resolved.

Note: This solution requires a certain level of technical expertise. If you’re not comfortable building Ruby from the source, you can wait until Ruby 3.3.1 is released or explore alternative solutions to compile assets in your Rails application.