LoginSignup
6
2

More than 3 years have passed since last update.

rbenv install 2.7.1が「no acceptable C compiler found in $PATH」「cannot load such file」により失敗する

Posted at

環境

  • rbenv 1.1.2-30-gc879cb0
  • ruby-build 20200520-12-g69ccbf4
  • Ubuntu 20.04 LTS (Focal Fossa) [Windows Subsystem for Linux 2; WSL2]

前提

rbenvおよびruby-buildの導入が完了し、rbenv-doctor scriptによる検証がOKであること。

$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /home/dev/.rbenv/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /home/dev/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20200520-12-g69ccbf4)
Counting installed Ruby versions: none
  There aren't any Ruby versions installed under `/home/dev/.rbenv/versions'.
  You can install Ruby versions like so: rbenv install 2.2.4
Checking RubyGems settings: OK
Auditing installed plugins: OK

問題

rbenv + ruby-build の導入完了後、rbenv install -v 2.7.1によって、Ruby2.7.1の導入を行ったが、以下のような原因により失敗した (エラー全文を掲載するとさすがに冗長なため、特徴的な部分を抜粋しています)

  • configure: error: no acceptable C compiler found in $PATH
  • cannot load such file -- openssl (LoadError)
  • cannot load such file -- digest/sha2.so (LoadError)

原因と対策

Rubyのビルドに必要なライブラリが不足していることが原因でした。ruby-buildのwikiにはRubyのビルドに必要なライブラリとそのインストール方法がOSごとにまとめられているページがあります。これを参考にして、自分の環境(Ubuntu)に不足しているライブラリのインストールを行ったあと、rbenv installを行うとRuby2.7.1を導入することができました。

sudo apt update 
sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev
6
2
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
6
2