Error loading shared library

Error loading shared library No such file or directory が出た場合

解決策:libc6-compat をインストールする

Sinatra を利用した簡単なアプリを MacBook(M1)で開発していて、いざ Linux 環境へデプロイするためには Docker build したときに発生。

/usr/local/bundle/gems/nokogiri-1.13.8-aarch64-linux/lib/nokogiri/extension.rb:7:in `require_relative': Error loading shared library No such file or directory (needed by /usr/local/bundle/gems/nokogiri-1.13.8-aarch64-linux/lib/nokogiri/3.0/ - /usr/local/bundle/gems/nokogiri-1.13.8-aarch64-linux/lib/nokogiri/3.0/ (LoadError)
        from /usr/local/bundle/gems/nokogiri-1.13.8-aarch64-linux/lib/nokogiri/extension.rb:7:in `<top (required)>'
        from /usr/local/bundle/gems/nokogiri-1.13.8-aarch64-linux/lib/nokogiri.rb:10:in `require_relative'
        from /usr/local/bundle/gems/nokogiri-1.13.8-aarch64-linux/lib/nokogiri.rb:10:in `<top (required)>'
Status Error: データの取得に失敗しました


=> ERROR [6/6] RUN bundle exec rails assets:precompile                                                                                                                                    0.5s 
 > [6/6] RUN bundle exec rails assets:precompile:                                                                                                                                               
#10 0.462 bundler: failed to load command: rails (/usr/local/bundle/bin/rails)                                                                                                                  
#10 0.462 /usr/local/bundle/gems/bundler-2.2.22/lib/bundler/spec_set.rb:41:in `block in for': Unable to find a spec satisfying sqlite3 (~> 1.4) in the set. Perhaps the lockfile is corrupted? Found sqlite3 (1.5.3-arm64-darwin) that did not match the current platform. (Bundler::GemNotFound)
#10 0.462 	from /usr/local/bundle/gems/bundler-2.2.22/lib/bundler/spec_set.rb:20:in `loop'
#10 0.462 	from /usr/local/bundle/gems/bundler-2.2.22/lib/bundler/spec_set.rb:20:in `for'


  • bundle lock --add-platform aarch64-linux
+ sqlite3 (1.5.3-aarch64-linux)
  sqlite3 (1.5.3-arm64-darwin)

+   aarch64-linux


  • aarch64-linux # Docker (M1)
  • arm64-darwin # Mac(M1)
  • x86_64-linux # Docker(Intel)
  • x86_64-darwin # Mac (Intel)
  • ruby
Installing Nokogiri - Nokogiri

Installing Nokogiri - Nokogiri

The Official Tutorial Archive™ of Nokogiri®

Bundler 2.2 and later has great multiplatform support and allows you to cache gems for multiple platforms. You can run commands like these to cause Bundler to fetch and cache gems for all the named platforms:

bundle lock --add-platform x86_64-darwin
bundle lock --add-platform x86_64-linux
bundle package --all-platforms