2 minutes
Alpine Ruby: Can’t load nokogiri
The issue
I was doing practice of Github workflow by making a basic task app using Rails
I was using
- ruby:3.1.2-alpine3.14 (for the base image)
- Rails 7.0.4
Initially, everything was going smoothly but once I shut down the computer one day and came to work on it again, I started getting error from Nokogiri every time I try to bundle install
in the container.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
The fix
I’ve tried a few things but the one solved the problem was adding
RUN apk add --no-cache libc6-compat && ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
to the Dockerfile that builds the image for ruby.
I came to this idea in through the following steps
I started the container and in the shell, I simply ran
gem install nokogiri
which worked
Then, in irb
, I tried to require nokogiri
.
Which threw an error like
Error loading shared library ld-linux-x86-64.so.2: No such file or directory
When I googled, I hit on this Qiita article, which said to run the command above.
It seems that it is based off of the stackoverflow article but tbh, I have no idea why it did the fix.
I’m just noting here so that someone who might have a similar problem can fix it. Or, future me might benefit from it once I remake the Dockerfile for another practice run 😅