(Linux|HomeBrew|Ruby)HomeBrewとRubyのインストール関連

ゴール:

やること:

  • HomeBrew(LinuxBrew)をインストール

  • rbenvインストール

  • rbenvでRubyのバージョンを管理する

環境:

  • Windows10上のWSL2(Ubuntu 18.04.6 LTS)

Rubyのインストール

$ sudo apt install ruby

HomeBrewのインストール

確認:

  • Installation successful
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

<<略>>

==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/masawa/.profile
    eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
- Install Homebrew's dependencies if you have sudo access:
    sudo apt-get install build-essential
  For more information, see:
    https://docs.brew.sh/Homebrew-on-Linux
- We recommend that you install GCC:
    brew install gcc
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

環境変数追加

$ echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/masawa/.profile
$ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

rbenvインストール

$ brew install rbenv

rbenvでRubyのバージョンを管理する

確認:

  • BUILD FAILED

  • error: no acceptable C compiler とログ出力されている。

参照:
ChromebookにHomebrew(Linuxbrew)をインストールする

$ rbenv install 3.1.2
Downloading ruby-3.1.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
Installing ruby-3.1.2...
ruby-build: using readline from homebrew

BUILD FAILED (Ubuntu 18.04 using ruby-build 20220426)

Inspect or clean up the working tree at /tmp/ruby-build.20220603094749.27208.cWN6BQ
Results logged to /tmp/ruby-build.20220603094749.27208.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.20220603094749.27208.cWN6BQ/ruby-3.1.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

Cコンパイラをインストール

$ sudo apt-get install build-essential curl file git

改めてrbenvでRubyのバージョンを管理する

確認:

  • BUILD FAILED

  • Try running apt-get install -y zlib1g-dev to fetch missing dependencies.

$ rbenv install 3.1.2
Downloading ruby-3.1.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
Installing ruby-3.1.2...
ruby-build: using readline from homebrew

BUILD FAILED (Ubuntu 18.04 using ruby-build 20220426)

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

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

Configure options used:
  --prefix=/home/masawa/.rbenv/versions/3.1.2
  --enable-shared
  --with-readline-dir=/home/linuxbrew/.linuxbrew/opt/readline
  LDFLAGS=-L/home/masawa/.rbenv/versions/3.1.2/lib
  CPPFLAGS=-I/home/masawa/.rbenv/versions/3.1.2/include

zlib1g-devをインストール

$ sudo apt-get install -y zlib1g-dev

改めてrbenvでRubyのバージョンを管理する

$ rbenv install 3.1.2
Downloading ruby-3.1.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
Installing ruby-3.1.2...
ruby-build: using readline from homebrew

確認

$ rbenv versions
* system
  3.1.2
$ rbenv global 3.1.2
$ rbenv versions
  system
* 3.1.2 (set by /home/masawa/.rbenv/version)

OK!