LoginSignup
8
4

More than 5 years have passed since last update.

Ubuntu 16.04 に Ruby 1.8.5 をインストールする

Posted at

年末なので Ubuntu 16.04 に Ruby 1.8.5 をインストールして動かしてみます。

必要なライブラリをインストールする

Ruby 1.8.5 をビルドするにあたって必要となるライブラリをインストールします。
ここで一つ問題になるのが、OpenSSL0.9.8を要求される点です。
OpenSSL1.0系ではビルドに失敗します。

OpenSSL0.9.8をインストールするために古いリポジトリを使います。

$ echo 'deb http://old-releases.ubuntu.com/ubuntu lucid-security main' | sudo tee /etc/apt/sources.list.d/lucid-security.list
$ sudo apt-get update

準備ができたのでインストールします。

$ sudo apt-get install zlib1g-dev
$ sudo apt-get install -t lucid-security libssl-dev

その他必要となるライブラリをインストールします。

$ sudo apt-get install build-essential libyaml-dev libxml2-dev libxslt1-dev libreadline-dev

ruby-build をインストールする

この辺は公式のドキュメントそのままです。
https://github.com/rbenv/ruby-build#installing-as-a-standalone-program-advanced

$ git clone https://github.com/rbenv/ruby-build.git
$ cd ruby-build
$ sudo ./install.sh

Ruby 1.8.5 をインストールする

さて ruby-build には ruby 1.8.5 の definition がいくつか用意されていますが、これはそのままでは使えません。
※ わかってるなら Pull-Request しろという話ですがすいませんとりあえずそのまま進みます。

以下は Ruby 1.8.5-p231 をインストールした際のログです。

$ ruby-build 1.8.5-p231 ~/ruby-1.8.5
Downloading ruby-1.8.5-p231.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.5-p231.tar.bz2
Installing ruby-1.8.5-p231...

WARNING: ruby-1.8.5-p231 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

Installed ruby-1.8.5-p231 to /home/yono/ruby-1.8.5

Downloading rubygems-1.3.7.tgz...
-> https://dqw8nmjcqpjn7.cloudfront.net/388b90ae6273f655507b10c8ba6bee9ea72e7d49c3e610025531cb8c3ba67c9d
Installing rubygems-1.3.7...

BUILD FAILED (Ubuntu 16.04 using ruby-build 20160913)

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

Last 10 log lines:
Last-Modified: Fri, 23 May 2014 08:48:13 GMT
ETag: "e85cfadd025ff6ab689375adbf344bbe"
Accept-Ranges: bytes
Server: AmazonS3
X-Cache: Miss from cloudfront
Via: 1.1 96275b125ac8a1ca0365ff6f864de90c.cloudfront.net (CloudFront)
X-Amz-Cf-Id: vCBUe9FY2sEYl9REEnO8B3qa17peFB7nYlqidlOnoNr37jn7rCdMHQ==

/tmp/ruby-build.20161104233606.31970/rubygems-1.3.7 /tmp/ruby-build.20161104233606.31970 ~
ERROR:  Expected Ruby version >= 1.8.6, is 1.8.5.231

rubygems のインストールに失敗しています。何故かと言うと、インストールしようとしている rubygems 1.3.7 が Ruby 1.8.6 以上を要求しているからです。

    required_version = Gem::Requirement.new '>= 1.8.6'

    unless required_version.satisfied_by? Gem.ruby_version then
      alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}"
      terminate_interaction 1
    end

rubygems 1.3.7 未満で Ruby 1.8.6 以上を要求しないバージョンを探してみると、rubygems 1.3.5 が該当しました。
ruby-build には Custom Definition という仕組みがあるのでそれを使って rubygems 1.3.5 をインストールするように変更してみましょう。
https://github.com/rbenv/ruby-build#custom-definitions

叩き台となる Ruby 1.8.5-p231 の definition を手元にコピーします。

$ cp ruby-build/share/ruby-build/1.8.5-p231 .

中身は以下のようになっています。

$ cat 1.8.5-p231
require_gcc
install_package "ruby-1.8.5-p231" "https://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.5-p231.tar.bz2#b31a8db0a3b538c28bca1c9b08a07eb55a39547fdaad00c045f073851019639c" warn_eol auto_tcltk standard
install_package "rubygems-1.3.7" "https://rubygems.org/rubygems/rubygems-1.3.7.tgz#388b90ae6273f655507b10c8ba6bee9ea72e7d49c3e610025531cb8c3ba67c9d" ruby

なんとなく3行目の rubygems-1.3.7rubygems-1.3.5 に変えるとよさそうです。末尾にハッシュ値が付いてるのでそれも記載する必要があります。

$ wget https://rubygems.org/rubygems/rubygems-1.3.5.tgz
$ sha256sum rubygems-1.3.5.tgz
c0928cc1ae54dedfb5f57ad3829882c1f90e42bc17bf50491aa6f93a937546ac  rubygems-1.3.5.tgz

これを元にして 1.8.5-p231 を修正します。

$ cat 1.8.5-p231
require_gcc
install_package "ruby-1.8.5-p231" "https://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.5-p231.tar.bz2#b31a8db0a3b538c28bca1c9b08a07eb55a39547fdaad00c045f073851019639c" warn_eol auto_tcltk standard
install_package "rubygems-1.3.5" "https://rubygems.org/rubygems/rubygems-1.3.5.tgz#c0928cc1ae54dedfb5f57ad3829882c1f90e42bc17bf50491aa6f93a937546ac" ruby

修正した 1.8.5-p231 を使って Ruby 1.8.5 をインストールします。 ruby-build の引数にファイルを指定すると、そのファイルの記述を元にしてインストールが進みます。

$ ruby-build ./1.8.5-p231 ~/ruby-1.8.5

ですがこのままだとエラーが出ます。

Downloading ruby-1.8.5-p231.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.5-p231.tar.bz2
Installing ruby-1.8.5-p231...

WARNING: ruby-1.8.5-p231 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.


BUILD FAILED (Ubuntu 16.04 using ruby-build 20160913)

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

Last 10 log lines:
                 from ossl.h:45,
                 from ossl_cipher.c:11:
/usr/include/openssl/bn.h:412:5: note: previous declaration of ‘BN_pseudo_rand_range’ was here
 int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range);
     ^
Makefile:176: ターゲット 'ossl_cipher.o' のレシピで失敗しました
make[1]: *** [ossl_cipher.o] エラー 1
make[1]: ディレクトリ '/tmp/ruby-build.20161115225857.13675/ruby-1.8.5-p231/ext/openssl' から出ます
Makefile:241: ターゲット 'all' のレシピで失敗しました
make: *** [all] エラー 1

半ば強引ですが openssl のヘッダファイルに手を加えます。
/usr/include/openssl/bn.h の411行目と412行目をコメントアウトします。

$ diff /usr/include/openssl/bn.h ./bn.h 
411,412c411,412
< int   BN_rand_range(BIGNUM *rnd, const BIGNUM *range);
< int   BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range);
---
> //int BN_rand_range(BIGNUM *rnd, const BIGNUM *range);
> //int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range);

これでビルドが通るようになりました。

$ ruby-build ./1.8.5-p231 ~/ruby-1.8.5
Downloading ruby-1.8.5-p231.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.5-p231.tar.bz2
Installing ruby-1.8.5-p231...

WARNING: ruby-1.8.5-p231 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

Installed ruby-1.8.5-p231 to /home/yono/ruby-1.8.5

Downloading rubygems-1.3.5.tgz...
-> https://rubygems.org/rubygems/rubygems-1.3.5.tgz
Installing rubygems-1.3.5...
Installed rubygems-1.3.5 to /home/yono/ruby-1.8.5

試しに動かしてみます。

$ ./ruby-1.8.5/bin/ruby -v
ruby 1.8.5 (2008-06-20 patchlevel 231) [x86_64-linux]

はい。

$ ./ruby-1.8.5/bin/irb
irb(main):001:0> newstyle_hash = {key: 'value'}
SyntaxError: compile error
(irb):1: odd number list for Hash
newstyle_hash = {key: 'value'}
                     ^
(irb):1: syntax error, unexpected ':', expecting '}'
newstyle_hash = {key: 'value'}
                     ^
(irb):1: syntax error, unexpected '}', expecting $end
    from (irb):1
    from :0

そうですね。

irb(main):002:0> oldstyle_hash = {:key => 'value'}
=> {:key=>"value"}

よっしゃ。

$ ./ruby-1.8.5/bin/gem source --list
*** CURRENT SOURCES ***

http://gems.rubyforge.org/

アッ。

$ ./ruby-1.8.5/bin/gem source --add https://rubygems.org/
https://rubygems.org/ added to sources
$ ./ruby-1.8.5/bin/gem source --remove http://gems.rubyforge.org/
http://gems.rubyforge.org/ removed from sources

ハイ。

$ ./ruby-1.8.5/bin/gem install -r rake -v 0.8.0
Successfully installed rake-0.8.0
1 gem installed
Installing ri documentation for rake-0.8.0...
Installing RDoc documentation for rake-0.8.0...

$ ./ruby-1.8.5/bin/gem install -r rails -v 1.2.6
Successfully installed activesupport-1.4.4
Successfully installed activerecord-1.15.6
Successfully installed actionpack-1.13.6
Successfully installed actionmailer-1.3.6
Successfully installed actionwebservice-1.2.6
Successfully installed rails-1.2.6
6 gems installed
Installing ri documentation for activesupport-1.4.4...
Installing ri documentation for activerecord-1.15.6...
Installing ri documentation for actionpack-1.13.6...
Installing ri documentation for actionmailer-1.3.6...
Installing ri documentation for actionwebservice-1.2.6...
Installing ri documentation for rails-1.2.6...
Installing RDoc documentation for activesupport-1.4.4...
Installing RDoc documentation for activerecord-1.15.6...
Installing RDoc documentation for actionpack-1.13.6...
Installing RDoc documentation for actionmailer-1.3.6...
Installing RDoc documentation for actionwebservice-1.2.6...
Installing RDoc documentation for rails-1.2.6...

こうして。

$ ./ruby-1.8.5/bin/rails blog
      create  
      create  app/controllers
      create  app/helpers
      create  app/models
      create  app/views/layouts
      create  config/environments
      create  components
      create  db
      create  doc
      create  lib
      create  lib/tasks
      create  log
      create  public/images
      create  public/javascripts
      create  public/stylesheets
      create  script/performance
      create  script/process
      create  test/fixtures
      create  test/functional
      create  test/integration
      create  test/mocks/development
      create  test/mocks/test
      create  test/unit
      create  vendor
      create  vendor/plugins
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  Rakefile
      create  README
      create  app/controllers/application.rb
      create  app/helpers/application_helper.rb
      create  test/test_helper.rb
      create  config/database.yml
      create  config/routes.rb
      create  public/.htaccess
      create  config/boot.rb
      create  config/environment.rb
      create  config/environments/production.rb
      create  config/environments/development.rb
      create  config/environments/test.rb
      create  script/about
      create  script/breakpointer
      create  script/console
      create  script/destroy
      create  script/generate
      create  script/performance/benchmarker
      create  script/performance/profiler
      create  script/process/reaper
      create  script/process/spawner
      create  script/process/inspector
      create  script/runner
      create  script/server
      create  script/plugin
      create  public/dispatch.rb
      create  public/dispatch.cgi
      create  public/dispatch.fcgi
      create  public/404.html
      create  public/500.html
      create  public/index.html
      create  public/favicon.ico
      create  public/robots.txt
      create  public/images/rails.png
      create  public/javascripts/prototype.js
      create  public/javascripts/effects.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/controls.js
      create  public/javascripts/application.js
      create  doc/README_FOR_APP
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log

こうじゃ。

長くなりそうなのでここまでにします。
こちらからは以上です。

8
4
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
8
4