Skip to content

Instantly share code, notes, and snippets.

@chie8842
Last active August 29, 2015 14:04
Show Gist options
  • Save chie8842/9c9a7f5525fdc6709f78 to your computer and use it in GitHub Desktop.
Save chie8842/9c9a7f5525fdc6709f78 to your computer and use it in GitHub Desktop.
ubuntuへのruby最新版(2.2.0-dev)インストール
UbuntuのEC2インスタンス上に、Ruby on Rails開発環境を構築する。
プロンプトは$がubuntuユーザ(一般ユーザ)、#がrootユーザ。
①rubyがインストールされていないことを確認する。
# ruby -v
The program 'ruby' can be found in the following packages:
* ruby
* ruby1.8
Try: apt-get install <selected package>
②インストール済みのパッケージを最新化する。
# apt-get update
・・・省略・・・
Reading package lists... Done
# apt-get upgrade
After this operation, 33.8 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
・・・省略・・・
update-initramfs: Generating /boot/initrd.img-3.13.0-29-generic
#
③ rubyインストールに必要なパッケージのインストール
#apt-get install build-essential git curl zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev sqlite3 libsqlite3-dev nodejs
・・・省略・・・
After this operation, 151 MB of additional disk space will be used.
Do you want to continue? [Y/n]y
・・・省略・・・
Processing triggers for libc-bin (2.19-0ubuntu6) ...
#
④rbenvのインストール・設定
rbenvとは、rubyの実行環境を管理するもの。
rvmとrbenvがあり、この二つは共存できない。
rbenvの方が、各アプリのディレクトリごとにrubyのバージョンを指定できるなど、
便利そうだし、評判もいいので、今回はrbenvを採用する。
ここの設定はubuntuユーザにスイッチして実施する。
# su - ubuntu
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
remote: Reusing existing pack: 1889, done.
remote: Total 1889 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1889/1889), 297.15 KiB | 115.00 KiB/s, done.
Resolving deltas: 100% (1182/1182), done.
Checking connectivity... done.
$echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$exec $SHELL
⑤ruby-buildのインストール
さらに、rbenvのプラグインである、ruby-buildをインストールする。
$ mkdir -p ~/.rbenv/plugins
$ cd ~/.rbenv/plugins
$ git clone git://github.com/sstephenson/ruby-build.git
Cloning into 'ruby-build'...
remote: Reusing existing pack: 3544, done.
remote: Total 3544 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3544/3544), 599.13 KiB | 159.00 KiB/s, done.
Resolving deltas: 100% (1708/1708), done.
Checking connectivity... done.
$
⑥rubyインストール
今回は、最新版の2.2.0-devをインストールしてみる。
まず、最新版を確認する。
$rbenv install -l
Available versions:
1.8.6-p383
1.8.6-p420
・・・省略・・・
2.1.1
2.1.2
2.2.0-dev←最新版
jruby-1.5.6
・・・省略・・・
ruby2.2.0-devをインストールする。
$rbenv install 2.2.0-dev
Cloning https://github.com/ruby/ruby.git...
Installing ruby-2.2.0-dev...
BUILD FAILED
Inspect or clean up the working tree at /tmp/ruby-build.20140716142534.17135
Results logged to /tmp/ruby-build.20140716142534.17135.log
Last 10 log lines:
/tmp/ruby-build.20140716142534.17135 ~/.rbenv/plugins
Cloning into 'ruby-2.2.0-dev'...
/tmp/ruby-build.20140716142534.17135/ruby-2.2.0-dev /tmp/ruby-build.20140716142534.17135 ~/.rbenv/plugins
/home/ubuntu/.rbenv/plugins/ruby-build/bin/ruby-build: line 463: autoconf: command not found
あれ、エラーがでた。
autoconfというのが足りないということなので、インストールする。
$sudo apt-get install autoconf
・・・省略・・・
After this operation, 3,995 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
・・・省略・・・
update-alternatives: using /usr/bin/automake-1.14 to provide /usr/bin/automake (automake) in auto mode
再度チャレンジ。
$rbenv install 2.2.0-dev
Cloning https://github.com/ruby/ruby.git...
Installing ruby-2.2.0-dev...
BUILD FAILED
Inspect or clean up the working tree at /tmp/ruby-build.20140716150823.18752
Results logged to /tmp/ruby-build.20140716150823.18752.log
Last 10 log lines:
/tmp/ruby-build.20140716150823.18752 ~
Cloning into 'ruby-2.2.0-dev'...
/tmp/ruby-build.20140716150823.18752/ruby-2.2.0-dev /tmp/ruby-build.20140716150823.18752 ~
executable host ruby is required. use --with-baseruby option.; false -C ./tool get-config_files config.guess
executable host ruby is required. use --with-baseruby option.; false -C ./tool get-config_files config.sub
configure: error: cannot run /bin/bash tool/config.sub
BUILD FAILED
Inspect or clean up the working tree at /tmp/ruby-build.20140716150823.18752
Results logged to /tmp/ruby-build.20140716150823.18752.log
Last 10 log lines:
/tmp/ruby-build.20140716150823.18752 ~
Cloning into 'ruby-2.2.0-dev'...
/tmp/ruby-build.20140716150823.18752/ruby-2.2.0-dev /tmp/ruby-build.20140716150823.18752 ~
executable host ruby is required. use --with-baseruby option.; false -C ./tool get-config_files config.guess
executable host ruby is required. use --with-baseruby option.; false -C ./tool get-config_files config.sub
configure: error: cannot run /bin/bash tool/config.sub
またおこられた。
executable host ruby is required.(ベースとなるrubyが入っていないよ)ということなので、apt-getでrubyをインストールする。
$sudo apt-get install ruby
・・・省略・・・
After this operation, 12.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
・・・省略・・・
Processing triggers for libc-bin (2.19-0ubuntu6) ...
$ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
ruby1.9.3がインストールされた。
またまたチャレンジ
$ rbenv install 2.2.0-dev
Cloning https://github.com/ruby/ruby.git...
Installing ruby-2.2.0-dev...
BUILD FAILED
Inspect or clean up the working tree at /tmp/ruby-build.20140716151056.19344
Results logged to /tmp/ruby-build.20140716151056.19344.log
Last 10 log lines:
compiling io.c
compiling marshal.c
compiling math.c
compiling node.c
compiling numeric.c
compiling object.c
compiling pack.c
generating parse.c
make: bison: Command not found
make: *** [parse.c] Error 127
・・・
今度はbisonというコマンドがないと。。。
インストール。
$sudo apt-get install bison
・・・省略・・・
After this operation, 1,816 kB of additional disk space will be used.
Do you want to continue? [Y/n]y
・・・省略・・・
update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode
こ、今度こそ・・・
$rbenv install 2.2.0-dev
$ rbenv install 2.2.0-dev
Cloning https://github.com/ruby/ruby.git...
Installing ruby-2.2.0-dev...
Installed ruby-2.2.0-dev to /home/ubuntu/.rbenv/versions/2.2.0-dev
やった!できた!
つづいてデフォルトで使用するrubyバージョンを、今インストールした2.2.0-devにする。
$ rbenv rehash
$ rbenv global 2.2.0-dev
最後に、rubyのバージョン確認を行う。
$ ruby -v
ruby 2.2.0dev (2014-07-16 trunk 46840) [x86_64-linux]
$ rbenv version
2.2.0-dev (set by /home/ubuntu/.rbenv/version)
$ which ruby
/home/ubuntu/.rbenv/shims/ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment