0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AlmaLinux 8 で commonmarker gem が動かなかった件

Posted at

Ruby で Markdown 形式のテキストを扱う gem として commonmarker がある。

手元の macOS や AlmaLinux 9 では普通に使えたが,AlmaLinux 8 では動かなかったのを,開発元に教えていただいた方法で解決した。

うまくいかなかったこと

ふつうに

gem install commonmarker

とすると,すんなりインストールできた。
確認:

$ gem list commonmarker

*** LOCAL GEMS ***

commonmarker (2.6.1 x86_64-linux)

バージョン番号のうしろに「x86_64-linux」が付いているのは,ソレ用のプリコンパイル版1であることを意味する。

しかし,動かない。require "commonmarker" しただけで以下のようなエラーが出る。

/usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker/extension.rb:13:in 'Kernel#require': cannot load such file -- commonmarker/commonmarker (LoadError)
	from /usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker/extension.rb:13:in '<top (required)>'
	from /usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker.rb:3:in 'Kernel#require_relative'
	from /usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker.rb:3:in '<top (required)>'
	from <internal:/usr/local/rbenv/versions/4.0.1/lib/ruby/4.0.0/rubygems/core_ext/kernel_require.rb>:144:in 'Kernel#require'
/usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker/extension.rb:7:in 'Kernel#require_relative': /lib64/libc.so.6: version `GLIBC_2.30' not found (required by /usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker/4.0/commonmarker.so) - /usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker/4.0/commonmarker.so (LoadError)
	from /usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker/extension.rb:7:in '<top (required)>'
	from /usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker.rb:3:in 'Kernel#require_relative'
	from /usr/local/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/commonmarker-2.6.1-x86_64-linux/lib/commonmarker.rb:3:in '<top (required)>'
	from <internal:/usr/local/rbenv/versions/4.0.1/lib/ruby/4.0.0/rubygems/core_ext/kernel_require.rb>:144:in 'Kernel#require'
<internal:/usr/local/rbenv/versions/4.0.1/lib/ruby/4.0.0/rubygems/core_ext/kernel_require.rb>:139:in 'Kernel#require': cannot load such file -- commonmarker (LoadError)

なんかごちゃごちゃ書いてるけど,要は「GLIBC_2.30 が無い」と。

各種バージョンは以下のとおり。

  • AlmaLinux release 8.10 (Cerulean Leopard)
  • ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [x86_64-linux]
  • commonmarker 2.6.1

AlmaLinux 9.7 (Moss Jungle Cat) では問題なかった。
Ruby は 3.4.8 も試したが 4.0.1 と同じだった。

commonmarker は最新版でなく古いものも試そうとしたが,さまざまな原因で諦めた。

glibc のバージョンが古い

ええと,glibc のバージョンはどうなってんだ?

$ sudo dnf info glibc

とやると「2.28」であった。

同様の問題は nokogiri でもあった:
Nokogiri が version `GLIBC_2.29' not found で読み込めない件 - Qiita

要は

  • AlmaLinux 8 を使う限り glibc のバージョンは上げられないので,プリコンパイル版は動かない
  • ローカルでコンパイルせよ

ということだ。

ローカルでコンパイルを試みる

commonmarker や nokogiri のように,プリコンパイル版が用意されている gem で,あえてローカルでコンパイルするインストール方法をとるには,以下の三つの方法がある。

  • gem install--platform ruby オプションを与える
  • Gemfile で gem メソッドに force_ruby_platform: true オプションを与える
  • .bundle/configBUNDLE_FORCE_RUBY_PLATFORM: "true" を記述

gem install

最初の一つは Bundler と無関係に実行できる。

以下のようにする

gem install --platform ruby

ただし,せっかくこれでインストールしても,Bundler を使うプロジェクトで bundle install すると,プリコンパイル版がさらにインストールされて使われてしまうことに注意。

また,Bundler を使わない場合でも,プリコンパイル版がインストール済みの場合はそちらが使われてしまうようなので,削除しておく必要がある。

残りの二つはいずれも Bundler を使う場合の方法。

Gemfile

Gemfile に

gem "commonmarker", force_ruby_platform: true

のように記述する。

AlmaLinux 8 でのみ force_ruby_platform: true を付けたいなら,ちょっと面倒だけど

Gemfile
redhat_release_path = "/etc/redhat-release"
if File.exist?(redhat_release_path) && File.read(redhat_release_path).start_with?("AlmaLinux release 8")
  gem "commonmarker", force_ruby_platform: true
else
  gem "commonmarker"
end

みたいに書く。

あるいは

Gemfile
require "etc"
if Etc.uname[:release].include?(".el8_")
  gem "commonmarker", force_ruby_platform: true
else
  gem "commonmarker"
end

だろうか。

.bundle/config

Bundler を使うプロジェクトのディレクトリーで

bundle config set force_ruby_platform true

とすると,.bundle/config というファイルが作られ

BUNDLE_FORCE_RUBY_PLATFORM: "true"

が書かれる(既にファイルがあった場合は追記される)。

すると,このプロジェクトで bundle install とか bundle update したときに,すべての gem についてこれが適用される。

結果

三つのいずれの方法を使っても同じだが,

ERROR:  Error installing commonmarker:

とエラーが出てインストールに失敗する。
全体は以下のとおり:

ERROR:  Error installing commonmarker:
	ERROR: Failed to build gem native extension.
current directory: /usr/local/rbenv/versions/3.4.8/lib/ruby/gems/3.4.0/gems/commonmarker-2.6.1/ext/commonmarker

/usr/local/rbenv/versions/3.4.8/bin/ruby extconf.rb
checking for gcc... yes
checking for g++... yes
checking for gcc-ar... yes
checking for cargo... yes
checking for install_name_tool... no
checking for $(CARGO_BUILD_TARGET)-install_name_tool... no
current directory: /usr/local/rbenv/versions/3.4.8/lib/ruby/gems/3.4.0/gems/commonmarker-2.6.1/ext/commonmarker
make -j3 DESTDIR= sitearchdir=./.gem.20260115-837501-owot26 sitelibdir=./.gem.20260115-837501-owot26 clean
current directory: /usr/local/rbenv/versions/3.4.8/lib/ruby/gems/3.4.0/gems/commonmarker-2.6.1/ext/commonmarker
make -j3 DESTDIR= sitearchdir=./.gem.20260115-837501-owot26 sitelibdir=./.gem.20260115-837501-owot26
generating target/release/libcommonmarker.so (release)
cargo rustc  --manifest-path ./Cargo.toml --target-dir target --lib --profile release -- -C linker=gcc -L native=/usr/local/rbenv/versions/3.4.8/lib -C link-arg=-lm -l pthread
Compiling proc-macro2 v1.0.103
Compiling unicode-ident v1.0.20
Compiling quote v1.0.41
Compiling shlex v1.3.0
Compiling memchr v2.7.6
Compiling glob v0.3.3
Compiling syn v2.0.108
Compiling clang-sys v1.8.1
Compiling libc v0.2.177
Compiling aho-corasick v1.1.4
Compiling regex-syntax v0.8.8
Compiling cfg-if v1.0.4
Compiling minimal-lexical v0.2.1
Compiling nom v7.1.3
Compiling libloading v0.8.9
Compiling regex-automata v0.4.13
Compiling either v1.15.0
Compiling bindgen v0.69.5
Compiling serde_core v1.0.228
Compiling itertools v0.12.1
Compiling regex v1.12.2
Compiling cexpr v0.6.0
Compiling rustc-hash v1.1.0
Compiling find-msvc-tools v0.1.4
Compiling bitflags v2.10.0
Compiling lazycell v1.3.0
Compiling lazy_static v1.5.0
Compiling cc v1.2.43
Compiling pkg-config v0.3.32
Compiling shell-words v1.1.0
Compiling strsim v0.11.1
Compiling ident_case v1.0.1
Compiling fnv v1.0.7
Compiling rustix v1.1.2
Compiling serde v1.0.228
Compiling darling_core v0.21.3
Compiling onig_sys v69.9.1
Compiling rb-sys-build v0.9.123
Compiling powerfmt v0.2.0
Compiling rb-sys-env v0.2.2
Compiling linux-raw-sys v0.11.0
Compiling rustversion v1.0.22
Compiling itoa v1.0.15
Compiling utf8parse v0.2.2
Compiling prettyplease v0.2.37
Compiling crc32fast v1.5.0
Compiling anstyle-parse v0.2.7
Compiling darling_macro v0.21.3
Compiling deranged v0.5.5
Compiling rb-sys v0.9.123
Compiling serde_json v1.0.145
Compiling simd-adler32 v0.3.7
Compiling time-core v0.1.6
Compiling colorchoice v1.0.4
Compiling siphasher v1.0.1
Compiling anstyle v1.0.13
Compiling anstyle-query v1.1.4
Compiling thiserror v2.0.17
Compiling adler2 v2.0.1
Compiling num-conv v0.1.0
Compiling is_terminal_polyfill v1.70.2
Compiling equivalent v1.0.2
Compiling tinyvec_macros v0.1.1
Compiling hashbrown v0.16.0
Compiling indexmap v2.12.0
Compiling tinyvec v1.10.0
Compiling anstream v0.6.21
Compiling time v0.3.44
Compiling miniz_oxide v0.8.9
Compiling phf_shared v0.11.3
Compiling terminal_size v0.4.3
Compiling darling v0.21.3
error: failed to run custom build command for rb-sys v0.9.123
Caused by:
process didn't exit successfully: /usr/local/rbenv/versions/3.4.8/lib/ruby/gems/3.4.0/gems/commonmarker-2.6.1/ext/commonmarker/target/release/build/rb-sys-dfa8e3f338f9ceff/build-script-main (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=RUBY
cargo:rerun-if-env-changed=RBCONFIG_CROSS_COMPILING
cargo:rerun-if-env-changed=RBCONFIG_RUBY_PROGRAM_VERSION
cargo:rerun-if-env-changed=RBCONFIG_ruby_install_name
cargo:rerun-if-env-changed=RBCONFIG_platform
cargo:rerun-if-env-changed=RUBY_ROOT
cargo:rerun-if-env-changed=RUBY_VERSION
cargo:rerun-if-env-changed=RUBY
cargo:rerun-if-changed=build/features.rs
cargo:rerun-if-changed=build/stable_api_config.rs
cargo:rerun-if-changed=build/version.rs
cargo:rerun-if-changed=build/main.rs
cargo:rerun-if-env-changed=RUBY_STATIC
cargo:rerun-if-env-changed=RBCONFIG_ENABLE_SHARED
cargo:rerun-if-env-changed=RBCONFIG_rubyhdrdir
cargo:rerun-if-env-changed=RBCONFIG_rubyarchhdrdir
cargo:rerun-if-env-changed=RBCONFIG_CPPFLAGS
cargo:rerun-if-env-changed=RBCONFIG_rubyhdrdir
cargo:rerun-if-env-changed=RBCONFIG_MAJOR
cargo:rerun-if-env-changed=RBCONFIG_MINOR
cargo:rerun-if-env-changed=TARGET
cargo:rerun-if-env-changed=TARGET
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
--- stderr
INFO: using bindgen with clang args: ["-I/usr/local/rbenv/versions/3.4.8/include/ruby-3.4.0", "-I/usr/local/rbenv/versions/3.4.8/include/ruby-3.4.0/x86_64-linux", "-fms-extensions", "-fstack-protector-strong", "-U_FORTIFY_SOURCE", "-D_FORTIFY_SOURCE=2", "-O3", "-fno-fast-math", "-ggdb3", "-Wall", "-Wextra", "-Wdeprecated-declarations", "-Wdiv-by-zero", "-Wduplicated-cond", "-Wimplicit-function-declaration", "-Wimplicit-int", "-Wpointer-arith", "-Wwrite-strings", "-Wold-style-definition", "-Wimplicit-fallthrough=0", "-Wmissing-noreturn", "-Wno-cast-function-type", "-Wno-constant-logical-operand", "-Wno-long-long", "-Wno-missing-field-initializers", "-Wno-overlength-strings", "-Wno-packed-bitfield-compat", "-Wno-parentheses-equality", "-Wno-self-assign", "-Wno-tautological-compare", "-Wno-unused-parameter", "-Wno-unused-value", "-Wsuggest-attribute=format", "-Wsuggest-attribute=noreturn", "-Wunused-variable", "-Wmisleading-indentation", "-Wundef"]
#include "ruby.h"
#ifdef HAVE_RUBY_DEBUG_H
#include "ruby/debug.h"
#endif
#ifdef HAVE_RUBY_DEFINES_H
#include "ruby/defines.h"
#endif
#ifdef HAVE_RUBY_ENCODING_H
#include "ruby/encoding.h"
#endif
#ifdef HAVE_RUBY_FIBER_SCHEDULER_H
#include "ruby/fiber/scheduler.h"
#endif
#ifdef HAVE_RUBY_INTERN_H
#include "ruby/intern.h"
#endif
#ifdef HAVE_RUBY_IO_H
#include "ruby/io.h"
#endif
#ifdef HAVE_RUBY_MEMORY_VIEW_H
#include "ruby/memory_view.h"
#endif
#ifdef HAVE_RUBY_MISSING_H
#include "ruby/missing.h"
#endif
#ifdef HAVE_RUBY_ONIGMO_H
#include "ruby/onigmo.h"
#endif
#ifdef HAVE_RUBY_ONIGURUMA_H
#include "ruby/oniguruma.h"
#endif
#ifdef HAVE_RUBY_RACTOR_H
#include "ruby/ractor.h"
#endif
#ifdef HAVE_RUBY_RANDOM_H
#include "ruby/random.h"
#endif
#ifdef HAVE_RUBY_RE_H
#include "ruby/re.h"
#endif
#ifdef HAVE_RUBY_REGEX_H
#include "ruby/regex.h"
#endif
#ifdef HAVE_RUBY_RUBY_H
#include "ruby/ruby.h"
#endif
#ifdef HAVE_RUBY_ST_H
#include "ruby/st.h"
#endif
#ifdef HAVE_RUBY_THREAD_H
#include "ruby/thread.h"
#endif
#ifdef HAVE_RUBY_THREAD_NATIVE_H
#include "ruby/thread_native.h"
#endif
#ifdef HAVE_RUBY_UTIL_H
#include "ruby/util.h"
#endif
#ifdef HAVE_RUBY_VERSION_H
#include "ruby/version.h"
#endif
#ifdef HAVE_RUBY_VM_H
#include "ruby/vm.h"
#endif
#ifdef HAVE_RUBY_WIN32_H
#include "ruby/win32.h"
#endif
#ifdef HAVE_RUBY_IO_BUFFER_H
#include "ruby/io/buffer.h"
#endif
#ifdef HAVE_RUBY_ATOMIC_H
#include "ruby/atomic.h"
#endif
struct rb_sys__Opaque__RString { struct RString dummy; };
struct rb_sys__Opaque__RArray { struct RArray dummy; };
struct rb_sys__Opaque__RData { struct RData dummy; };
struct rb_sys__Opaque__RTypedData { struct RTypedData dummy; };
struct rb_sys__Opaque__rb_matchext_struct { struct rb_matchext_struct dummy; };
struct rb_sys__Opaque__rb_internal_thread_event_data { struct rb_internal_thread_event_data dummy; };
struct rb_sys__Opaque__rb_io_internal_buffer { struct rb_io_internal_buffer dummy; };
thread 'main' (838810) panicked at /home/XXXX/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bindgen-0.69.5/lib.rs:622:31:
Unable to find libclang: "couldn't find any valid shared libraries matching: ['libclang.so', 'libclang-.so', 'libclang.so.', 'libclang-.so.'], set the LIBCLANG_PATH environment variable to a path where one of these files can be found (invalid: [])"
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
make: *** [Makefile:573: target/release/libcommonmarker.so] エラー 101
make failed, exit code 2
Gem files will remain installed in /usr/local/rbenv/versions/3.4.8/lib/ruby/gems/3.4.0/gems/commonmarker-2.6.1 for inspection.
Results logged to /usr/local/rbenv/versions/3.4.8/lib/ruby/gems/3.4.0/extensions/x86_64-linux/3.4.0/commonmarker-2.6.1/gem_make.out

これを読み解こうとしたが,知識が無さすぎて諦めた。

開発元に泣きつき解決

commonmarker gem のリポジトリーに issue を立てた:
https://github.com/gjtorikian/commonmarker/issues/434

非常に素早く的確なアドバイスがいただけて,わずか 10 時間で完全解決した。

「libclang-dev のインストールが必要なのでは」とのことだったが,AlmaLinux ではそこをちょっと読み替えて,clang-devel をインストールすればいい。

エラーメッセージからこれが読み取れるようになりたいものだ。

ともかく

sudo dnf install clang-devel

しておけば,コンパイルが無事にできて commonmarker がインストールできることが分かった。

  1. commonmarker は拡張ライブラリーであって,コンパイルが必要な部分を内包しているのだが,さまざまなプラットフォーム用に事前にコンパイルしたものも用意されている。これを使わず,インストールするマシン上でコンパイルすることもできる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?