LoginSignup
5
5

More than 5 years have passed since last update.

rubyをソースからビルドしてrbenvで使えるようにする

Posted at

実行環境

  • Mac OS X 10.11.2

前提

  • gccが使えていること
% gcc -v
gcc: warning: couldn't understand kern.osversion '15.2.0
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc49/4.9-20140330/libexec/gcc/x86_64-apple-darwin13.1.0/4.9.0/lto-wrapper
Target: x86_64-apple-darwin13.1.0
Configured with: ../configure --build=x86_64-apple-darwin13.1.0 --prefix=/usr/local/Cellar/gcc49/4.9-20140330 --enable-languages=c,c++,objc,obj-c++ --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp4 --with-mpfr=/usr/local/opt/mpfr2 --with-mpc=/usr/local/opt/libmpc08 --with-cloog=/usr/local/opt/cloog018 --with-isl=/usr/local/opt/isl011 --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 4.9.0 20140330 (experimental) (GCC)

インストール手順

https://github.com/ruby/ruby にしたがってインストール

gitからrubyのソースコードを取ってきて移動

% git clone git://github.com/ruby/ruby.git
% cd ruby

./configure の生成

% autoconf

./configureの実行

以下の点に注意
1. 自分の環境の場合opensslをhomebrewでインストールしているため,そのパスを指定する必要がある
2. rbenvで使う場合インストール先を変える

# opensslの場所を確認し,opensslの場所と出力先を指定して実行
# homebrewでopensslを入れてパスを通している場合以下の様になる
% brew --prefix openssl
/usr/local/opt/openssl

# ここではrbenvで使えるようにしたいので.rbenv/versions以下に指定
# rubyのバージョン名は今回は適当に日付(20151221)にしておく(任意設定可)
% ./configure --prefix=$HOME/.rbenv/versions/20151221 --with-opt-dir=/usr/local/opt/openssl 

makeの実行

# 並列数は任意で
% make -j4

make check & install

# テスト等を行う場合
% make check

% make install

rbenvで使えることを確認

% rbenv versions # インストールしたrubyが追加されている(ここでは20151221)
% rbenv local 20151221
% ruby -v
ruby 2.3.0dev (2015-12-20 trunk 53220) [x86_64-darwin15]
5
5
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
5
5