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?

macでgem installが失敗した時の解決メモ

Last updated at Posted at 2025-05-10

困りごと

githubで職務経歴書を作成しようと思い立ち、jekyllを知り、自分のmacに入れようと思ったが、途中でmakeエラーがでてインストールできなかった。

結論

  • rubyのバージョン切り替え/管理をchrubyからasdfに変更したら解決
  • その際にchrubyでインストールしていたrubyも削除した
  • なぜchruby環境でエラーとなるのかは不明

解決までのメモ

rubyの管理をasdfに移行したものの、gemでインストールする時のログに表示される作業ディレクトリがchrubyの時のものであった。ので、すべてのrubyを一旦削除し、asdfで入れ直すことで解決した。
chatGPTに聞いても検討はずれな(一般的な)答えしかもらえなかったが、Issueの議論からヒントを見つけられた。
実はruby環境を導入したのは初なのでそれもいけなかった。

エラーが出るまでにやっていたこと

jekyllをインストールしたいがエラー
どうやらeventmachineのインストールでこけている様子

gem install jekyll     
Building native extensions. This could take a while...
ERROR:  Error installing jekyll:
	ERROR: Failed to build gem native extension.

    current directory: /Users/username/.gem/ruby/3.4.1/gems/eventmachine-1.2.7/ext
/Users/username/.rubies/ruby-3.4.1/bin/ruby extconf.rb
checking for pkg-config for openssl... ["-I/opt/homebrew/Cellar/openssl@3/3.5.0/include ", "-L/opt/homebrew/Cellar/openssl@3/3.5.0/lib", "-lssl -lcrypto"]
-----
Using OpenSSL from pkg-config -I/opt/homebrew/Cellar/openssl@3/3.5.0/include  && -L/opt/homebrew/Cellar/openssl@3/3.5.0/lib && -lssl -lcrypto
-----
checking for -lcrypto... yes
...
checking for CLOCK_MONOTONIC in time.h... yes
CXXFLAGS=-fdeclspec
creating Makefile

current directory: /Users/username/.gem/ruby/3.4.1/gems/eventmachine-1.2.7/ext
make DESTDIR\= sitearchdir\=./.gem.20250509-5018-m955ku sitelibdir\=./.gem.20250509-5018-m955ku clean

current directory: /Users/username/.gem/ruby/3.4.1/gems/eventmachine-1.2.7/ext
make DESTDIR\= sitearchdir\=./.gem.20250509-5018-m955ku sitelibdir\=./.gem.20250509-5018-m955ku
compiling binder.cpp
make: *** [binder.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/username/.gem/ruby/3.4.1/gems/eventmachine-1.2.7 for inspection.
Results logged to /Users/username/.gem/ruby/3.4.1/extensions/arm64-darwin-24/3.4.0-static/eventmachine-1.2.7/gem_make.out

eventmachineの個別インストールでも同じエラー

[username@/Users/username]gem install eventmachine                                     
Building native extensions. This could take a while...
ERROR:  Error installing eventmachine:
	ERROR: Failed to build gem native extension.

    current directory: /Users/username/.gem/ruby/3.4.1/gems/eventmachine-1.2.7/ext
/Users/username/.asdf/installs/ruby/3.4.3/bin/ruby extconf.rb
checking for pkg-config for openssl... ["-I/opt/homebrew/Cellar/openssl@3/3.5.0/include ", "-L/opt/homebrew/Cellar/openssl@3/3.5.0/lib", "-lssl -lcrypto"]
-----
Using OpenSSL from pkg-config -I/opt/homebrew/Cellar/openssl@3/3.5.0/include  && -L/opt/homebrew/Cellar/openssl@3/3.5.0/lib && -lssl -lcrypto
-----
checking for -lcrypto... yes
...
checking for CLOCK_MONOTONIC in time.h... yes
CXXFLAGS=-fdeclspec
creating Makefile

current directory: /Users/username/.gem/ruby/3.4.1/gems/eventmachine-1.2.7/ext
make DESTDIR\= sitearchdir\=./.gem.20250510-31881-k4cc9r sitelibdir\=./.gem.20250510-31881-k4cc9r clean

current directory: /Users/username/.gem/ruby/3.4.1/gems/eventmachine-1.2.7/ext
make DESTDIR\= sitearchdir\=./.gem.20250510-31881-k4cc9r sitelibdir\=./.gem.20250510-31881-k4cc9r
compiling binder.cpp
make: *** [binder.o] Error 1

make failed, exit code 2

解決のためにやったこと

#chrubyでインストールしたrubyの削除
sudo rm -rf ~/.rubies

#asdfで入れたrubyも一旦全部削除
asdf list ruby
asdf uninstall ruby 3.4.0

#クリーンになったのち、asdfでrubyをインストール
asdf install ruby 3.4.0

#jekyll install
asdf set ruby 3.4.3
gem install jekyll

ほか解決に向けてやったこと

XCodeのclang環境が悪いかもと思いXcodeのupdate 効果なし
XCodeのリセット 効果なし

sudo xcode-select --reset

gemのクリーンアップ 効果なし

gem cleanup

参考情報

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?