Linuxbrew

作成日 : 2013-11-17
最終更新日 :

Linuxbrewとは

Linuxbrew とは、MacOS の Homebrew の Linux 版である。 Homebrew とは何かというと、同じプログラムの複数のバージョンを同時に管理できる仕組み (パッケージ管理システム)である。 ちなみに英語で homebrew とは自家醸造を意味する。 このファイルの hejmfarita はエスペラントで「自家製の」を意味する。

以上の記事を書いた 2013 年当時は Homebrew とは独立に Linuxbrew があったが、 2019 年に Linuxbrew は本家 Homebrew に統合された。以下は Linuxbrew 時代の覚書である。 ついでにいえば、Vine Linux は 2021 年 5 月に VineSeed を除きすべてのリリースを停止している。

Vine Linux でインストール挑戦

Vine Linux は全体的に入っているパッケージが古いので、Linuxbrew が役に立ちそうだ。ではがんばって導入してみよう。 リンクに従い、下記パッケージを導入した。

$ sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev

ところが、Vine Linux 6.3 では上記のうち、libbz-dev 以下の開発用ライブラリが軒並みみつからず、インストールできない。 仕方ない。無謀でもこのまま Linuxbrew を導入してみたらどうなるだろうか。実施した結果は次の通りで、あえなく撃沈した。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
==> This script will install:
$HOME/.linuxbrew/bin/brew
$HOME/.linuxbrew/Library/...
$HOME/.linuxbrew/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
fatal: Unable to find remote helper for 'https'
Failed during: git fetch origin master:refs/remotes/origin/master -n

この原因は、git をコンパイルしたときに curl ライブラリがリンクされていなかったことにある。

$ ./configure --with-curl
$ make
$ sudo make install

ここで curl とは非対話的 http(s) 通信ソフトで、 私の認識では wget と並ぶ(wget の進化版か)。 さて、curl つきの git を作って起動させてみたが、 次の表示が出て失敗してしまった。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
  ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/uninstall)"
(省略)

仕方がないので、一度きれいにした。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/uninstall)"
which: no bre in ($PATH)
Warning: This script will remove:
$HOME/.cache/Homebrew/
$HOME/.cache/.linuxbrew/.git/
Are you sure you want to uninstall Homebrew? [y/N] y
==> Removing Homebrew installation...
==> Removing empty directories...
==> Homebrew uninstalled!

再度挑戦したら、うまくいったようだ。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install)"
==> This script will install:
$HOME/.linuxbrew/bin/brew
$HOME/.linuxbrew/Library/...
$HOME/.linuxbrew/share/doc/homebrew
$HOME/.linuxbrew/share/man/man1/brew.1
$HOME/.linuxbrew/share/zsh/site-functions/_brew
$HOME/.linuxbrew/etc/bash_completion.d/brew
$HOME/.linuxbrew/.cache/Homebrew/

Press RETURN to continue or any other key to abort
==> Downloading and installing Linuxbrew...
(中略)
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  http://docs.brew.sh/Analytics.html

==> Tapping homebrew/core
(中略)
==> Installation successful!
==> Next steps
Install the Linuxbrew dependencies:

Debian, Ubuntu, etc.:
  `sudo apt-get install build-essential`

Fedora, Red Hat, CentOS, etc.:
  `sudo yum groupinstall 'Development Tools'`

See http://linuxbrew.sh/#dependencies for more information.

Add to your ~/.bash_profile by running
  echo 'export PATH="$HOME/.linuxbrew/bin:$PATH"' >>~/.bash_profile
  echo 'export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"' >>~/.bash_profile
  echo 'export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"' >>~/.bash_profile

We recommend you install GCC by running `brew install gcc`.
Run `brew help` to get started
Further documentation: https://git.io/brew-docs
==> Homebrew has enabled anonymous aggregate user behaviour analytics
Read the analytics documentation (and how to opt-out) here:
  https://git.io/brew-analytics

なお、実際には、$HOME のところは実在するディレクトリとなっている。

なんだかんだで自家醸造ができたようだ。

応用:rbenv

rbenv とは ruby (rb) のバージョンを環境 (env) によって切り替えられるツールである。 現在私の rbenv はどういうわけか入っている。

$ which rbenv
$HOME/.rbenv/bin/rbenv
$ rbenv -v
rbenv 1.1.0-2-g4f8925a

さて、rbenv が使えるか。 rbenv でインストール可能なバージョン一覧が出るというのだが。

$ rbenv install -l
rbenv: no such command `install'

バカにしとるのか!仕方がない。brew を使って rbenv をインストールするか。

$ brew rbenv
==> Installing dependencies for rbenv: m4, autoconf, pkg-config, zlib, gpatch, openssl, ruby-build
==> Installing rbenv dependency: m4
==> Downloading https://linuxbrew.bintray.com/bottles/m4-1.4.18.x86_64_linux.bot
######################################################################## 100.0%
==> Pouring m4-1.4.18.x86_64_linux.bottle.tar.gz
   $HOME/.linuxbrew/Cellar/m4/1.4.18: 13 files, 1.1MB
==> Installing rbenv dependency: autoconf
==> Downloading https://linuxbrew.bintray.com/bottles/autoconf-2.69.x86_64_linux
######################################################################## 100.0%
==> Pouring autoconf-2.69.x86_64_linux.bottle.4.tar.gz
==> Caveats

Emacs Lisp files have been installed to:
  $HOME/.linuxbrew/share/emacs/site-lisp/autoconf
==> Summary
  $HOME/.linuxbrew/Cellar/autoconf/2.69: 70 files, 3MB
==> Installing rbenv dependency: pkg-config
Error: pkg-config cannot be built with any available compilers.
Install Clang or brew install gcc

これはインストールの連鎖、インストール地獄ですな。 こうなったら毒食わば皿まで、brew install gcc やってやろうじゃないの。

$ brew install gcc
==> Installing dependencies for gcc: zlib, gmp, mpfr, libmpc, isl
==> Installing gcc dependency: zlib
(中略)
==> Installing gcc dependency: gmp
(中略)
==> Installing gcc dependency: mpfr
(中略)
==> Installing gcc dependency: libmpc
(中略)
==> Installing gcc dependency: isl
(中略)
==> Installing gcc
(後略)

なんとかうまくいったようだ。こんどこそ、か。

$ brew install rbenv
==> Installing dependencies for rbenv: pkg-config, gpatch, openssl, ruby-build
==> Installing rbenv dependency: pkg-config
==> Downloading https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=$HOME/.linuxbrew/Cellar/pkg-config/0.29.2 --disable-host-tool --with-i
==> make
Last 15 lines from $HOME/.cache/Homebrew/Logs/pkg-config/02.make:
See  for instructions.
make[6]: *** [libglib_2_0_la-grand.lo] エラー 1
make[6]: *** 未完了のジョブを待っています....
make[6]: ディレクトリ `/tmp/pkg-config-20170423-11689-1f9dyyf/pkg-config-0.29.2/glib/glib' から出ます
make[5]: *** [all-recursive] エラー 1
make[5]: ディレクトリ `/tmp/pkg-config-20170423-11689-1f9dyyf/pkg-config-0.29.2/glib/glib' から出ます
make[4]: *** [all] エラー 2
make[4]: ディレクトリ `/tmp/pkg-config-20170423-11689-1f9dyyf/pkg-config-0.29.2/glib/glib' から出ます
make[3]: *** [all-recursive] エラー 1
make[3]: ディレクトリ `/tmp/pkg-config-20170423-11689-1f9dyyf/pkg-config-0.29.2/glib' から出ます
make[2]: *** [all] エラー 2
make[2]: ディレクトリ `/tmp/pkg-config-20170423-11689-1f9dyyf/pkg-config-0.29.2/glib' から出ます
make[1]: *** [all-recursive] エラー 1
make[1]: ディレクトリ `/tmp/pkg-config-20170423-11689-1f9dyyf/pkg-config-0.29.2' から出ます
make: *** [all] エラー 2

READ THIS: https://github.com/Linuxbrew/brew/blob/master/docs/Troubleshooting.md#troubleshooting

These open issues may also help:
pkg-config: better tests https://github.com/Homebrew/homebrew-core/pull/12522

何度やってもエラーでうまくいかない。 原因を探るのは諦め、gpatch, openssl, ruby-build のそれぞれのインストールを行う。

$ brew install gpatch

これは問題なくインストールできた。

$ brew install openssl
==> Downloading https://www.openssl.org/source/openssl-1.0.2k.tar.gz
######################################################################## 100.0%
==> Downloading https://github.com/openssl/openssl/pull/1524.patch
==> Downloading from https://patch-diff.githubusercontent.com/raw/openssl/openss
######################################################################## 100.0%
==> Patching
==> Applying 1524.patch
patching file Configure
Hunk #1 succeeded at 1723 (offset 2 lines).
==> perl ./Configure --prefix=$HOME/.linuxbrew/Cellar/openssl/1.0.2k --op
==> make depend
==> make
Last 15 lines from $HOME/.cache/Homebrew/Logs/openssl/03.make:
b_print.c: In function 'roundv':
b_print.c:607:5: internal compiler error: Illegal instruction
     if (value >= 0.5)
     ^
0x7fecebecfcff ???
	/home/vbuilder/rpm/BUILD/glibc-2.23/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.
make[2]: *** [b_print.o] Error 1
make[2]: Leaving directory `/tmp/openssl-20170423-4341-x7kult/openssl-1.0.2k/crypto/bio'
make[1]: *** [subdirs] エラー 1
make[1]: ディレクトリ `/tmp/openssl-20170423-4341-x7kult/openssl-1.0.2k/crypto' から出ます
make: *** [build_crypto] エラー 1

READ THIS: https://github.com/Linuxbrew/brew/blob/master/docs/Troubleshooting.md#troubleshooting

These open issues may also help:
sslscan: add option to statically link OpenSSL https://github.com/Homebrew/homebrew-core/pull/10556
Curl formula complains that the `--with-openssl` does not exist when run with `--nghttp2`. https://github.com/Homebrew/homebrew-core/issues/12409

ruby-build はどうだろうか。

$ brew install ruby-build
==> Installing dependencies for ruby-build: pkg-config, openssl
==> Installing ruby-build dependency: pkg-config
(後略)

そうか、ruby-build が pkg-config と openssl に依存しているのだから、どうしようもないな。

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
  /usr/local/bin/x86_64-unknown-linux-gnu-pkg-config
  /usr/local/bin/pkg-config
  /usr/local/bin/gauche-config
  /usr/local/bin/curl-config

ところが http://qiita.com/ringo/items/4351c6aee70ed6f346c8 をみたら、 apt でインストールできるようになってました。 とのことだったのでやってみた。

$ sudo apt install rbenv ruby-build
パッケージリストを読みこんでいます... 完了
依存情報ツリーを作成しています... 完了        
以下のパッケージが新たにインストールされます:
  rbenv ruby-build
アップグレード: 0 個, 新規インストール: 2 個, 削除: 0 個, 保留: 0 個
104kB のアーカイブを取得する必要があります。
展開後に 226kB のディスク容量が追加消費されます。
取得:1 http://updates.vinelinux.org 6.5/x86_64/plus ruby-build 0.0.20170407-1vl6 [80.4kB]
取得:2 http://updates.vinelinux.org 6.5/x86_64/plus rbenv 1.1.0.20170407-1vl6 [23.6kB]
104kB を 0s で取得しました (563kB/s)
変更を適用しています...
準備中                                ############################## [100%]
更新/インストール中
  rbenv-1.1.0.20170407-1vl6.noarch       ############################## [100%]
You probably want to execute the following line to add rbenv to your shell
echo 'eval "$(rbenv init -)"' >> /root/.bash_profile
  ruby-build-0.0.20170407-1vl6.noarch    ############################## [100%]
完了
$ rbenv install
rbenv: no such command `install'

これには、ruby-build を入れればいいようなのだが。

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Cloning into '$HOME/.rbenv/plugins/ruby-build'...
git-remote-https: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory

そういえば、もののはずみで curl を remove していた。もう一回入れなおす。

$ sudo apt install curl
パッケージリストを読みこんでいます... 完了
依存情報ツリーを作成しています... 完了        
以下のパッケージが新たにインストールされます:
  curl
アップグレード: 0 個, 新規インストール: 1 個, 削除: 0 個, 保留: 0 個
0B/598kB のアーカイブを取得する必要があります。
展開後に 1556kB のディスク容量が追加消費されます。
変更を適用しています...
準備中                                ############################## [100%]
更新/インストール中
  curl-7.51.0-1vl6.x86_64                ############################## [100%]
/sbin/ldconfig: /usr/lib/libbrscandec2.so.1 はシンボリックリンクではありません

/sbin/ldconfig: /usr/lib/libbrcolm2.so.1 はシンボリックリンクではありません

完了

よし。こんどこそ ruby-build が入るだろう。

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Cloning into '$HOME/.rbenv/plugins/ruby-build'...
remote: Counting objects: 7484, done.
remote: Total 7484 (delta 0), reused 0 (delta 0), pack-reused 7483
Receiving objects: 100% (7484/7484), 1.52 MiB | 1.94 MiB/s, done.
Resolving deltas: 100% (4531/4531), done.
$

では次に、ruby 2.4.0 を入れることにする。

$ rbenv install 2.4.0
Downloading ruby-2.4.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.0.tar.bz2
Installing ruby-2.4.0...

BUILD FAILED (Linux 4.4.52-2vl6 using ruby-build 20170405-2-g3b15693)

Inspect or clean up the working tree at /tmp/ruby-build.20170423163549.9737
Results logged to /tmp/ruby-build.20170423163549.9737.log
(後略)

これはコンパイルに失敗したことを示している。ログを見てみると、驚くべきことがわかった。

(前略)
compiling dmydln.c
In file included from ./include/ruby/intern.h:32:0,
                 from ./include/ruby/ruby.h:2001,
                 from dmydln.c:1:
$HOME/.linuxbrew/Cellar/gcc/5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/include/varargs.h:4:2: error: #error "GCC no longer implements <varargs.h>."
 #error "GCC no longer implements <varargs.h>."
  ^
$HOME/.linuxbrew/Cellar/gcc/5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/include/varargs.h:5:2: error: #error "Revise your code to use <stdarg.h>."
 #error "Revise your code to use <stdarg.h>."
  ^
In file included from ./include/ruby/intern.h:32:0,
                 from ./include/ruby/ruby.h:2001,
                 from ./include/ruby.h:33,
                 from main.c:13:

うーん、これだけみればオリジナルのソースにある <varargs.h> を <stdarg.h> に書き換えればいいのだけれど。 多分これは新しい gcc を使ったために出たのだろう。新しい gcc は Homebrew している。

$ gcc --version
gcc (Homebrew gcc 5.3.0) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
(後略)

一方、古い gcc もあったと思う。

$ /usr/bin/gcc --version
gcc (GCC) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.
(後略)

古いほうならコンパイルできるのかな。2.2.0 を作ってしまった。

$ export CC="/usr/bin/gcc"; rbenv install 2.4.0; unset CC
Downloading ruby-2.4.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.0.tar.bz2
Installing ruby-2.4.0...

BUILD FAILED (Linux 4.4.52-2vl6 using ruby-build 20170405-2-g3b15693)

Inspect or clean up the working tree at /tmp/ruby-build.20170423163549.9737
Results logged to /tmp/ruby-build.20170423163549.9737.log
(後略)

Ubuntu などの場合

$ sudo add-apt-repository "deb https://cli-assets.heroku.com/branches/stable/apt ./" $ curl -L https://cli-assets.heroku.com/apt/release.key | sudo apt-key add - $ sudo apt-get update $ sudo apt-get install heroku

その他の場合

$ # wget --no-check-certificate https://cli-assets.heroku.com/branches/stable/heroku-OS-ARCH.tar.gz
$ wget --no-check-certificate https://cli-assets.heroku.com/branches/stable/heroku-linux-386.tar.gz
$ mkdir -p /usr/local/lib /usr/local/bin
$ sudo tar -xvzf heroku-OS-ARCH.tar.gz -C /usr/local/lib 
$ sudo ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku

PostgreSQL

さて、PostgreSQL のインストールはうまくいくだろうか。なお、$HOME を ~ と略記している。

$ brew install postgresql
==> Tapping linuxbrew/extra
Cloning into '~/.linuxbrew/Library/Taps/linuxbrew/homebrew-extra'...
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 12 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (12/12), done.
Tapped 4 formulae (43 files, 159.5KB)
==> Installing dependencies for postgresql: openssl, pkg-config, ncurses, readline, libxml2, libxslt, xz, gdbm, berkeley-db, expat, perl, util-linux
==> Installing postgresql dependency: openssl
==> Downloading https://www.openssl.org/source/openssl-1.0.2k.tar.gz
Already downloaded: ~/.cache/Homebrew/openssl-1.0.2k.tar.gz
==> Downloading https://github.com/openssl/openssl/pull/1524.patch
Already downloaded: ~/.cache/Homebrew/openssl--patch-853a15755d3bc2b561d64c4f5d58a7ff4885e5cdbacbf429ce93b477e0d3d68e.patch
==> Patching
==> Applying 1524.patch
patching file Configure
Hunk #1 succeeded at 1723 (offset 2 lines).
==> perl ./Configure --prefix=~/.linuxbrew/Cellar/openssl/1.0.2k --openssldir=~/.linuxbrew/etc/openssl no
==> make depend
==> make
Last 15 lines from ~/.cache/Homebrew/Logs/openssl/03.make:
b_print.c: In function 'roundv':
b_print.c:607:5: internal compiler error: Illegal instruction
     if (value >= 0.5)
     ^
0x7f1c3b578cff ???
	/home/vbuilder/rpm/BUILD/glibc-2.23/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
Please submit a full bug report,

リンク

まりんきょ学問所UNIX 手習い > Linuxbrew


MARUYAMA Satosi