在CentOS 5.x上通过Yum安装Ruby 1.8.6
CentOS 5.5默认安装的Ruby版本是1.8.5,但是最新版本的RubyGems要求Ruby的最低版本也是1.8.6,而更糟的是yum源都还不能提供一个高版本的Ruby
如果你想在CentOS 5.x系统上使用最新版本的RubyGems,你需要安装Ruby 1.8.6或者更新的版本,以下方法是使用Yum安装Ruby 1.8.6的方法,而1.8.6更高的版本似乎还不能通过常规的Yum源安装(CentOS, CentOS-Test 或者 RPMForge Yum repos).
64-bit:
$ sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm $ sudo rpm -Uvh http://download.elff.bravenet.com/5/x86_64/elff-release-5-3.noarch.rpm $ sudo yum install ruby ruby-shadow ruby-ri ruby-rdoc gcc gcc-c++ ruby-devel -y
$ ruby -v
ruby 1.8.6 (2010-02-05 patchlevel 399) [x86_64-linux]
32-bit:
$ sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm $ sudo rpm -Uvh http://download.elff.bravenet.com/5/i386/elff-release-5-3.noarch.rpm $ sudo yum install ruby ruby-shadow ruby-ri ruby-rdoc gcc gcc-c++ ruby-devel -y
$ ruby -v
ruby 1.8.6 (2010-02-05 patchlevel 399) [x86_64-linux]
安装RubyGems:
$ wget http://rubyforge.org/frs/?group_id=126&release_id=43601 $ tar xzvf rubygems-1.3.7.tgz $ cd cd rubygems-1.3.7 $ sudo ruby setup.rb
$ gem --version
1.3.7
在CentOS 5.x上通过编译安装Ruby 1.9.x
首先删除已经安装的Ruby:
sudo yum erase ruby ruby-libs ruby-mode ruby-rdoc ruby-irb ruby-ri ruby-docs
安装编译需要的相关工具和包:
sudo yum install openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p180.tar.gz
tar zxvf ruby-1.9.2-p180.tar.gz
cd ruby-1.9.2-p180
./configure --enable-shared --enable-pthread --prefix=/usr
make&&make install
......
compiling zlib
make[1]: Entering directory `/opt/ruby-1.9.2-p180/ext/zlib'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/opt/ruby-1.9.2-p180/ext/zlib'
making ruby
make[1]: Entering directory `/opt/ruby-1.9.2-p180'
make[1]: `ruby' is up to date.
make[1]: Leaving directory `/opt/ruby-1.9.2-p180'
Generating RDoc documentation
./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb ./tool/runruby.rb --extout=.ext -- "./bin/rdoc" --no-force-update --all --ri --op ".ext/rdoc" "."
No newer files.
./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb ./tool/rbinstall.rb --make="make" --dest-dir="" --extout=".ext" --mflags="" --make-flags="" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --install=all --rdoc-output=".ext/rdoc"
installing binary commands: /usr/bin
installing base libraries: /usr/lib
installing arch files: /usr/lib/ruby/1.9.1/x86_64-linux
installing extension objects: /usr/lib/ruby/1.9.1/x86_64-linux
installing extension objects: /usr/lib/ruby/site_ruby/1.9.1/x86_64-linux
installing extension objects: /usr/lib/ruby/vendor_ruby/1.9.1/x86_64-linux
installing extension headers: /usr/include/ruby-1.9.1/x86_64-linux
installing extension scripts: /usr/lib/ruby/1.9.1
installing extension scripts: /usr/lib/ruby/site_ruby/1.9.1
installing extension scripts: /usr/lib/ruby/vendor_ruby/1.9.1
installing extension headers: /usr/include/ruby-1.9.1/ruby
installing rdoc: /usr/share/ri/1.9.1/system
installing capi-docs: /usr/share/doc/ruby
installing command scripts: /usr/bin
installing library scripts: /usr/lib/ruby/1.9.1
installing common headers: /usr/include/ruby-1.9.1
installing manpages: /usr/share/man/man1
installing default gems: /usr/lib/ruby/gems/1.9.1 (cache, doc, gems, specifications)
rake 0.8.7
rdoc 2.5.8
minitest 1.6.0
注意:Ruby 1.9.2已经包含RubyGems,所以没有必要再单独安装RubyGems,如果安装会有以下报错:
rubygems-1.3.7/lib/rubygems/source_index.rb:68:in `installed_spec_directories': undefined method `path' for Gem:Module (NoMethodError)
测试安装结果:
[root@localhost ruby-1.9.2-p180]# ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
[root@localhost ruby-1.9.2-p180]# gem --version
1.3.7
安装Rails:
[root@localhost ruby-1.9.2-p180]# gem install rails
Successfully installed activesupport-3.0.7 Successfully installed builder-2.1.2 Successfully installed i18n-0.5.0 Successfully installed activemodel-3.0.7 Successfully installed rack-1.2.2 Successfully installed rack-test-0.5.7 Successfully installed rack-mount-0.6.14 Successfully installed tzinfo-0.3.27 Successfully installed abstract-1.0.0 Successfully installed erubis-2.6.6 Successfully installed actionpack-3.0.7 Successfully installed arel-2.0.9 Successfully installed activerecord-3.0.7 Successfully installed activeresource-3.0.7 Successfully installed mime-types-1.16 Successfully installed polyglot-0.3.1 Successfully installed treetop-1.4.9 Successfully installed mail-2.2.19 Successfully installed actionmailer-3.0.7 Successfully installed thor-0.14.6 Successfully installed railties-3.0.7 Successfully installed bundler-1.0.12 Successfully installed rails-3.0.7 23 gems installed Installing ri documentation for activesupport-3.0.7... Installing ri documentation for builder-2.1.2... Installing ri documentation for i18n-0.5.0... Installing ri documentation for activemodel-3.0.7... Installing ri documentation for rack-1.2.2... Installing ri documentation for rack-test-0.5.7... Installing ri documentation for rack-mount-0.6.14... Installing ri documentation for tzinfo-0.3.27... Installing ri documentation for abstract-1.0.0... Installing ri documentation for erubis-2.6.6... Installing ri documentation for actionpack-3.0.7... Installing ri documentation for arel-2.0.9... Installing ri documentation for activerecord-3.0.7... Installing ri documentation for activeresource-3.0.7... Installing ri documentation for mime-types-1.16... Installing ri documentation for polyglot-0.3.1... Installing ri documentation for treetop-1.4.9... Installing ri documentation for mail-2.2.19... Installing ri documentation for actionmailer-3.0.7... Installing ri documentation for thor-0.14.6... Installing ri documentation for railties-3.0.7... Installing ri documentation for bundler-1.0.12... Installing ri documentation for rails-3.0.7... Installing RDoc documentation for activesupport-3.0.7... Installing RDoc documentation for builder-2.1.2... Installing RDoc documentation for i18n-0.5.0... Installing RDoc documentation for activemodel-3.0.7... Installing RDoc documentation for rack-1.2.2... Installing RDoc documentation for rack-test-0.5.7... Installing RDoc documentation for rack-mount-0.6.14... Installing RDoc documentation for tzinfo-0.3.27... Installing RDoc documentation for abstract-1.0.0... Installing RDoc documentation for erubis-2.6.6... Installing RDoc documentation for actionpack-3.0.7... Installing RDoc documentation for arel-2.0.9... Installing RDoc documentation for activerecord-3.0.7... Installing RDoc documentation for activeresource-3.0.7... Installing RDoc documentation for mime-types-1.16... Installing RDoc documentation for polyglot-0.3.1... Installing RDoc documentation for treetop-1.4.9... Installing RDoc documentation for mail-2.2.19... Installing RDoc documentation for actionmailer-3.0.7... Installing RDoc documentation for thor-0.14.6... Installing RDoc documentation for railties-3.0.7... Installing RDoc documentation for bundler-1.0.12... Installing RDoc documentation for rails-3.0.7...
测试Rails程序
[root@localhost ~]# rails new blog
create
create README
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/application.html.erb
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create log
create log/server.log
create log/production.log
create log/development.log
create log/test.log
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create public/images
create public/images/rails.png
create public/stylesheets
create public/stylesheets/.gitkeep
create public/javascripts
create public/javascripts/application.js
create public/javascripts/controls.js
create public/javascripts/dragdrop.js
create public/javascripts/effects.js
create public/javascripts/prototype.js
create public/javascripts/rails.js
create script
create script/rails
create test
create test/fixtures
create test/functional
create test/integration
create test/performance/browsing_test.rb
create test/test_helper.rb
create test/unit
create tmp
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create vendor/plugins
create vendor/plugins/.gitkeep
[root@localhost blog]# script/rails --help
Could not find gem 'sqlite3 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
sqlite3-ruby 需要 sqlite3.6.16+ 版本。
而yum安装sqlite-devel貌似只能3.3.6版本,因此需要自己编译安装更高的版本。
[root@localhost blog]# yum install sqlite-devel
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * addons: ftp.iij.ad.jp * base: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * updates: ftp.iij.ad.jp Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package sqlite-devel.i386 0:3.3.6-5 set to be updated --> Processing Dependency: libsqlite3.so.0 for package: sqlite-devel ---> Package sqlite-devel.x86_64 0:3.3.6-5 set to be updated --> Running transaction check ---> Package sqlite.i386 0:3.3.6-5 set to be updated --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================= Installing: sqlite-devel i386 3.3.6-5 base 257 k sqlite-devel x86_64 3.3.6-5 base 257 k Installing for dependencies: sqlite i386 3.3.6-5 base 213 k Transaction Summary ======================================================================================================================================================================= Install 3 Package(s) Upgrade 0 Package(s) Total download size: 727 k Is this ok [y/N]: N
下载高版本sqlite
wget http://www.sqlite.org/sqlite-amalgamation-3.6.23.1.tar.gz tar zxvf sqlite-amalgamation-3.6.23.1.tar.gz cd sqlite-3.6.23.1
安装sqlite
./configure --prefix=/opt/sqlite make && make install
安装sqlite3-ruby
[root@localhost sqlite-3.6.23.1]# gem install sqlite3-ruby -- --with-sqlite3-dir=/opt/sqlite
Building native extensions. This could take a while... ####################################################### Hello! The sqlite3-ruby gem has changed it's name to just sqlite3. Rather than installing `sqlite3-ruby`, you should install `sqlite3`. Please update your dependencies accordingly. Thanks from the Ruby sqlite3 team! <3 <3 <3 <3 ####################################################### Successfully installed sqlite3-1.3.3 Successfully installed sqlite3-ruby-1.3.3 2 gems installed Installing ri documentation for sqlite3-1.3.3... Installing ri documentation for sqlite3-ruby-1.3.3... Installing RDoc documentation for sqlite3-1.3.3... Installing RDoc documentation for sqlite3-ruby-1.3.3...
安装完成,再次运行
[root@localhost blog]# script/rails --help
Usage: rails COMMAND [ARGS]
The most common rails commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
server Start the Rails server (short-cut alias: "s")
dbconsole Start a console for the database specified in config/database.yml
(short-cut alias: "db")
new Create a new Rails application. "rails new my_app" creates a
new application called MyApp in "./my_app"
In addition to those, there are:
application Generate the Rails application code
destroy Undo code generated with "generate"
benchmarker See how fast a piece of code runs
profiler Get profile information from a piece of code
plugin Install a plugin
runner Run a piece of code in the application environment
All commands can be run with -h for more information.
运行rails程序
[root@localhost blog]# script/rails s
=> Booting WEBrick => Rails 3.0.7 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2011-04-29 04:26:18] INFO WEBrick 1.3.1 [2011-04-29 04:26:18] INFO ruby 1.9.2 (2011-02-18) [x86_64-linux] [2011-04-29 04:26:18] INFO WEBrick::HTTPServer#start: pid=5658 port=3000 [2011-04-29 05:21:31] INFO going to shutdown ... [2011-04-29 05:21:31] INFO WEBrick::HTTPServer#start done. 原文地址:http://www.flatws.cn/article/program/ruby/2011-05-14/25841.html
本文介绍如何在CentOS5.x系统上通过Yum安装Ruby 1.8.6以及通过编译方式安装Ruby 1.9.x,并详细记录了安装过程中的关键步骤。此外,还介绍了如何安装RubyGems以及Rails框架,包括解决依赖问题的方法。
2131

被折叠的 条评论
为什么被折叠?



