Fail to install nokogiri with Debian Slim
Published: 2022-01-17 02:24:27

# Nokogiri Install Note

I use the container image `ruby:2.6.0-slim` and am faced following errors.

```
$ gem install nokogiri
$ rails g ...

ERROR: It looks like you're trying to use Nokogiri as a precompiled native gem on a system with glibc < 2.17:

  /lib/aarch64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /usr/local/bundle/gems/nokogiri-1.13.1-aarch64-linux/lib/nokogiri/2.6/nokogiri.so) - /usr/local/bundle/gems/nokogiri-1.13.1-aarch64-linux/lib/nokogiri/2.6/nokogiri.so

  If that's the case, then please install Nokogiri via the `ruby` platform gem:
      gem install nokogiri --platform=ruby
  or:
      bundle config set force_ruby_platform true

  Please visit https://nokogiri.org/tutorials/installing_nokogiri.html for more help.


ERROR: It looks like you're trying to use Nokogiri as a precompiled native gem on a system with glibc < 2.17:

  /lib/aarch64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /usr/local/bundle/gems/nokogiri-1.13.1-aarch64-linux/lib/nokogiri/2.6/nokogiri.so) - /usr/local/bundle/gems/nokogiri-1.13.1-aarch64-linux/lib/nokogiri/2.6/nokogiri.so

  If that's the case, then please install Nokogiri via the `ruby` platform gem:
      gem install nokogiri --platform=ruby
  or:
      bundle config set force_ruby_platform true

  Please visit https://nokogiri.org/tutorials/installing_nokogiri.html for more help.

/usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': /lib/aarch64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /usr/local/bundle/gems/nokogiri-1.13.1-aarch64-linux/lib/nokogiri/2.6/nokogiri.so) - /usr/local/bundle/gems/nokogiri-1.13.1-aarch64-linux/lib/nokogiri/2.6/nokogiri.so (LoadError)
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:88:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `require_relative'
	from /usr/local/bundle/gems/nokogiri-1.13.1-aarch64-linux/lib/nokogiri/extension.rb:7:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:88:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `require_relative'
	from /usr/local/bundle/gems/nokogiri-1.13.1-aarch64-linux/lib/nokogiri.rb:10:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:105:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/loofah-2.13.0/lib/loofah.rb:4:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:105:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/rails-html-sanitizer-1.4.2/lib/rails-html-sanitizer.rb:2:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:105:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/actionview-5.2.6/lib/action_view/helpers/sanitize_helper.rb:4:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:88:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/actionview-5.2.6/lib/action_view/helpers.rb:62:in `<module:Helpers>'
	from /usr/local/bundle/gems/actionview-5.2.6/lib/action_view/helpers.rb:6:in `<module:ActionView>'
	from /usr/local/bundle/gems/actionview-5.2.6/lib/action_view/helpers.rb:5:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:105:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/sprockets-rails-3.4.2/lib/sprockets/rails/context.rb:1:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:105:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/sprockets-rails-3.4.2/lib/sprockets/railtie.rb:10:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:105:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/sass-rails-5.1.0/lib/sass/rails/railtie.rb:3:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:105:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/sass-rails-5.1.0/lib/sass/rails.rb:11:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:105:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/sass-rails-5.1.0/lib/sass-rails.rb:1:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:105:in `register'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/lib/ruby/2.6.0/bundler/runtime.rb:81:in `block (2 levels) in require'
	from /usr/local/lib/ruby/2.6.0/bundler/runtime.rb:76:in `each'
	from /usr/local/lib/ruby/2.6.0/bundler/runtime.rb:76:in `block in require'
	from /usr/local/lib/ruby/2.6.0/bundler/runtime.rb:65:in `each'
	from /usr/local/lib/ruby/2.6.0/bundler/runtime.rb:65:in `require'
	from /usr/local/lib/ruby/2.6.0/bundler.rb:114:in `require'
	from /sample/config/application.rb:7:in `<top (required)>'
	from /usr/local/bundle/gems/spring-2.1.1/lib/spring/application.rb:92:in `require'
	from /usr/local/bundle/gems/spring-2.1.1/lib/spring/application.rb:92:in `preload'
	from /usr/local/bundle/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve'
	from /usr/local/bundle/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
	from /usr/local/bundle/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
	from /usr/local/bundle/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
	from /usr/local/bundle/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
	from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from -e:1:in `<main>'

```

I cheked glibc version. The version is `2.24`. It is lower than `2.29`.

```
$ ldd --version
ldd (Debian GLIBC 2.24-11+deb9u3) 2.24
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
```

I changed the base docker image version from `ruby:2.6.0-slim` to `ruby:2.6.8-bullseye`.

This is because the version of glibc depends on base OS version. When you need to use a new glibc, you have to a use new OS version.