LoginSignup
2
0

More than 3 years have passed since last update.

WSL2上で動くUbuntu20.04でrbenvでのrubyインストールが失敗する問題への対応

Last updated at Posted at 2020-12-07

問題

タイトル通りですが、Windows10のWSL2上で動くUbuntu20.04でrbenvでのrubyインストールが失敗する問題に直面しました。

環境

  • Windows10 Pro 64bit
  • WSL2
  • Ubuntu 20.04.1 LTS
  • ruby-build 20201118(以下のコマンドよりrbenvに問題ないこと確認済み)
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

Checking for `rbenv' in PATH: /home/linuxbrew/.linuxbrew/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /home/linuxbrew/.linuxbrew/bin/rbenv-install (ruby-build 20201118)
Counting installed Ruby versions: none
  There aren't any Ruby versions installed under `/home/rikoroku/.rbenv/versions'.
  You can install Ruby versions like so: rbenv install 2.2.4
Checking RubyGems settings: OK
Auditing installed plugins: OK

実行コマンド

$ rbenv install 2.6.3

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "ja_JP.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Downloading ruby-2.6.3.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.3.tar.bz2
Installing ruby-2.6.3...
ruby-build: using readline from homebrew

BUILD FAILED (Ubuntu 20.04 using ruby-build 20201118)

Inspect or clean up the working tree at /tmp/ruby-build.20201207224042.2086.9ACiG6
Results logged to /tmp/ruby-build.20201207224042.2086.log

Last 10 log lines:
/tmp/ruby-build.20201207224042.2086.9ACiG6/ruby-2.6.3 /tmp/ruby-build.20201207224042.2086.9ACiG6 ~
checking for ruby... false
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/tmp/ruby-build.20201207224042.2086.9ACiG6/ruby-2.6.3':
configure: error: C compiler cannot create executables
See `config.log' for more details

解決方法

以下のコマンドを実行し解決しました。タイトルにWSL2とありますが関係なさそうですね。。

また、今回は開発用として仮想環境上で行ったというのと、公式パッケージマネージャーから入れたというので特に気にせず実行しましたが、本番環境であればミニマルOSでパッケージの詳細を確認したうえで必要パッケージのみをインストールしなければいけないですね。パッケージの分だけ依存管理をしなければならず脆弱性放置の危険性も上がりますので。

$ 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

問題解決までの過程

不要だとは思いますが、参考までに解決までの過程を記載しておきます。

1. config.logを確認

エラー文 See 'config.log' for more details にもある通り、まずはこのファイルを確認しました。

$ less /tmp/ruby-build.20201207222731.172.GUu0j7/ruby-2.6.3/config.log

一瞬、ファイルどこにあるの?と迷いましたが、 less コマンドで /tmp/ ディレクトリにいきtab補完したところディレクトリがあるのに気づき、ディレクトリに入ったところ config.log ファイルがありました。

$ less /tmp/ruby-build.2020120722
ruby-build.20201207222731.172.GUu0j7/  ruby-build.20201207223551.918.log
ruby-build.20201207222731.172.log      ruby-build.20201207224042.2086.9ACiG6/
ruby-build.20201207223551.918.TMNgQy/  ruby-build.20201207224042.2086.log

ちなみに config.log ファイルの中身を見ましたが、Cのヘッダーファイルの情報や変数情報、プラットフォームの情報などがありましたが、僕的には有意な情報を得られませんでした。

2. error: C compiler cannot create executables で検索

https://github.com/rbenv/ruby-build/issues/779 にいきつき、Did you follow the instructions on the wiki for Fedora and try again? のコメントを発見。wikiに遷移。

3. ruby-buildのwikiのTroubleshootingを参考

C compiler cannot create executables の説明より、ビルドに必要なパッケージがインストールされてない可能性があることを知り、Suggested build environmentから「解決方法」で実行したコマンドを把握しました。

2
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
2
0