Apple Silicon(M1芯片)Mac安装capybara-webkit及相关依赖失败求助
I’ve hit this exact roadblock on my M1 MacBook before—this error comes down to openssl@1.0 not supporting ARM64 architecture natively, which causes the assembly-level failures you’re seeing in the x86_64cpuid.s file. Here’s a step-by-step fix that worked for me:
Step 1: Use Rosetta 2 to Run an x86_64 Terminal
Legacy packages like qt@4 and openssl@1.0 were built for x86_64 systems, so running your commands through a Rosetta-emulated terminal avoids architecture mismatches:
- Find Terminal in your Applications/Utilities folder
- Right-click it → Duplicate, rename the copy to "Terminal (Rosetta)"
- Right-click the new terminal → Get Info → Check "Open using Rosetta"
- Launch this Rosetta terminal to proceed with installations.
Step 2: Reinstall Dependencies with x86_64 Homebrew
The Rosetta terminal will use the x86_64 version of Homebrew (located in /usr/local) instead of the ARM version in /opt/homebrew. Run these commands in the Rosetta terminal:
# Uninstall any broken ARM versions first (if needed) brew uninstall --force qt@4 qt-webkit@2.3 openssl@1.0 # Tap and install x86_64-compatible versions brew tap cartr/qt4 brew install qt@4 brew install qt-webkit@2.3 brew install openssl@1.0
Step 3: Install capybara-webkit with Correct Environment Variables
Before installing the gem, point it to the x86_64 libraries we just installed:
export PATH="/usr/local/opt/qt@4/bin:$PATH" export LDFLAGS="-L/usr/local/opt/openssl@1.0/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.0/include" gem install capybara-webkit
Alternative: Switch to a Modern Capybara Driver
If you’re open to alternatives, capybara-webkit is pretty outdated. For M1 Macs, Capybara with Selenium and Chrome works flawlessly without these legacy dependency headaches:
- Install the native ARM64 version of Chrome for Mac
- Install the required gem:
gem install selenium-webdriver - Update your test suite’s Capybara setup:
Capybara.default_driver = :selenium_chrome
Quick note: The error log you shared confirms the issue is architecture-related—
x86_64cpuid.sis trying to run x86-specific assembly instructions on ARM64, which throws invalid operand errors. Rosetta translates these instructions correctly to work on M1 chips.
内容的提问来源于stack exchange,提问作者John Ross

