LoginSignup
1
0

More than 1 year has passed since last update.

自作PCにwsl2で開発環境を整える~ruby導入編~

Last updated at Posted at 2021-06-25

Abstract

前回anyenvを導入しました。
次は、Railsを動かすため、rbenvを入れてrubyを導入します。

rbenvの導入

anyenv install rbenv

必要であればPATHを通してください。
前回紹介した方法でanyenvを導入すればPATHを通す必要はないはずです。

導入の確認

rbenv -v

インストール可能なものの確認

rbenv install --list-all

allをつけないとstableな最新版しか出てきません。

ruby導入

それではrubyを入れます。
結論から言うと、ここでrbenv install <VERSION>をしても、エラーを吐くはずです。
まずは必要なパッケージをインストールします。

C Compiler

C/C++のコンパイラがないと以下のようなエラーを吐きます。

user@host:<directory>$ rbenv install 3.0.0
Downloading ruby-3.0.0.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz
Installing ruby-3.0.0...

BUILD FAILED (Ubuntu 20.04 using ruby-build 20210611-1-g1b477ae)

Inspect or clean up the working tree at /tmp/ruby-build.20210625134041.169.hZmhg7
Results logged to /tmp/ruby-build.20210625134041.169.log

Last 10 log lines:
checking target system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for clang... no
checking for cc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-build.20210625134041.169.hZmhg7/ruby-3.0.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

というわけで、rubyのインストールのために必要なC/C++のコンパイラを準備します。
おすすめはbuild-essentialです。

sudo apt install build-essential

libssl-devとzlib1g-dev

ここで実行すると、以下のエラーが出ました。

user@host:<direcotry>$ rbenv install 3.0.0
Downloading ruby-3.0.0.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz
Installing ruby-3.0.0...

BUILD FAILED (Ubuntu 20.04 using ruby-build 20210611-1-g1b477ae)

Inspect or clean up the working tree at /tmp/ruby-build.20210625134444.5800.6HNitQ
Results logged to /tmp/ruby-build.20210625134444.5800.log

Last 10 log lines:
The Ruby openssl extension was not compiled.
The Ruby zlib extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `apt-get install -y libssl-dev zlib1g-dev` to fetch missing dependencies.

Configure options used:
  --prefix=/home/ennean/.anyenv/envs/rbenv/versions/3.0.0
  --enable-shared
  LDFLAGS=-L/home/ennean/.anyenv/envs/rbenv/versions/3.0.0/lib
  CPPFLAGS=-I/home/ennean/.anyenv/envs/rbenv/versions/3.0.0/include

で、入れろと言われたので入れます。

sudo apt-get install -y libssl-dev zlib1g-dev

ruby本体

ここまで来れば、やっと本体を導入できるはずです。

rbenv install 3.0.0
rbenv local 3.0.0

確認

ruby -v

バージョンが返ってきたら導入成功です。

バックナンバーと次回予告

初回:WSL導入編
前回:anyenv導入編
次回:Postgre SQL導入編

参考

configure: error: no acceptable C compiler found in $PATHエラー解消方法
rbenvでrubyをインストールできなかった。 @mnbdyunan
rbenvでRubyをインストールする @ryoyakawai

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