uzullaの日記

本家:about等:Twitter
 | 

2008-01-31

Rubyの最新版を入れる

| 16:42

最近はサーバーに最初からRubyが入っている事も多いけれど、yumでいれてもバージョンがちょっと古かったりするので。

以下は某専用サーバーに最新の(といっても1.86系の)Ruby野良ビルドしてRuby on Railsが動く所まで。


--

http://www.ruby-lang.org/ja/downloads/

からファイルをDLする。安定版スナップショットを利用。

ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz

tar xvzf  stable-snapshot.tar.gz
cd ruby
./configure --prefix=/usr/local/ruby ((これはお好みで、今回Snapshotを入れたので、一応分けた))
make all
make install
/usr/local/ruby/bin/ruby -v

必要なら、/usr/bin/rubyとかにSymlinkを張る。

railsを動かすのが目標なので、まずはgemを入れる。

wget http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz
tar xvzf rubygems-1.0.1.tgz
cd rubygems-1.0.1
ruby setup.rb

さーて早速rails

[root@sv rubygems-1.0.1]# /usr/local/ruby/bin/gem install rails
/usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- zlib (LoadError)
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/package.rb:10
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/format.rb:9
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/installer.rb:11
 ... 11 levels...
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:103:in `process_args'
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:74:in `run'
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:39:in `run'
from /usr/local/ruby/bin/gem:22

うおっと、なんか足りてない。

zlibのサポート?

yum install zlib-devel
cd /usr/local/src/ruby/ext/zlib/
ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
make all
make install

[root@sv zlib]# /usr/local/ruby/bin/gem install rails
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rake-0.8.1
Successfully installed activesupport-2.0.2
Successfully installed activerecord-2.0.2
Successfully installed actionpack-2.0.2
Successfully installed actionmailer-2.0.2
Successfully installed activeresource-2.0.2
Successfully installed rails-2.0.2
7 gems installed
Installing ri documentation for rake-0.8.1...
Installing ri documentation for activesupport-2.0.2...
Installing ri documentation for activerecord-2.0.2...
Installing ri documentation for actionpack-2.0.2...
Installing ri documentation for actionmailer-2.0.2...
Installing ri documentation for activeresource-2.0.2...
Installing RDoc documentation for rake-0.8.1...
Installing RDoc documentation for activesupport-2.0.2...
Installing RDoc documentation for activerecord-2.0.2...
Installing RDoc documentation for actionpack-2.0.2...
Installing RDoc documentation for actionmailer-2.0.2...
Installing RDoc documentation for activeresource-2.0.2...

オッケー動いた。

さて、作ったRailsサーバーにUPして、回答して、WEBrickで試し起動…

[uzulla@sv votttttttte]$ ruby script/server 
=> Booting WEBrick...
/usr/local/ruby//lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:159:in `require_frameworks': no such file to load -- openssl (RuntimeError)
from /usr/local/ruby//lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:88:in `process'
from /usr/local/ruby//lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:49:in `send'
from /usr/local/ruby//lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:49:in `run'
from /home/uzulla/votttttttte/config/environment.rb:13
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /usr/local/ruby//lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /usr/local/ruby//lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
 ... 7 levels...
from /usr/local/ruby//lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/ruby//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from script/server:3

あれ、またコケた。

今度はOpensslか

yum install openssl
cd /usr/local/src/ruby/ext/openssl
ruby extconf.rb
make all
make intall

よし、これでWEBrickが動く様になった。

create databaseしたし、rake db:migrateしよう

あれ、rake入ってないや。

/usr/local/ruby/bin/gem install rake

今度こそrake…あれ?DBにつながんない?

mysqldのUNIXドメイン接続に失敗している

Railsデフォルトは/tmp/mysql.sockだけど、このサーバーだと違うんだな。

vi myrail/conf/database.yaml
--
production:
  adapter: mysql
  encoding: utf8
  database: votttttttte_production
  username: ユーザー
  password: パスワード
  host: localhost
  socket: /var/lib/mysql/mysql.sock(追記)

これでOK、マイグレートも実行も成功。

無事Railsが動く様になりました。

 |