CentOS安装Ruby,Rails运行环境

CentOS安装Ruby,Rails运行环境
RVM是一个命令行工具,可以提供一个便捷的多版本ruby环境的管理和切换
官方网站:https://rvm.io/
RVM安装:
# \curl -sSL https://get.rvm.io | bash -s stable
第一次运行,会出现error,原因是由于证书问题导致,使用-k命令跳过!
# \curl -sSL https://get.rvm.io -k | bash -s stable
执行上述命令后,发现无法下载软件包,执行以下操作:
# echo insecure >> ~/.curlrc
完成上述操作,就可以安装rvm了!
# \curl -sSL https://get.rvm.io | bash -s stable
RVM改用淘宝下载源,提高ruby等软件安装速度
# sed -i 's!ftp.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db
Ruby安装:
首先ruby会有必要的套件需要安装,通过yum安装套件
yum install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev
列出已知的ruby版本
# rvm list known
安装其中的版本
# rvm install 2.0.0
出现下列错误
Error running 'requirements_centos_update_system ruby-2.0.0-p353',
showing last 15 lines of /usr/local/rvm/log/1392712886_ruby-2.0.0-p353/update_system.log
   }
-bash: yum-config-manager: command not found
Error installing EPEL, it is required for libyaml-devel,
either there was an error installing EPEL package,
or there was problem checking if libyaml-devel is available / installed.
Requirements installation failed with status: 127.
原因是由于libyaml-devel没有安装,通过yum安装即可
# yum install libyaml-devel
再次运行rvm安装ruby
查看ruby版本
# ruby -v
查看gem版本(安装ruby会自动安装gem)
# gem -v
RubyGem默认源安装慢,可以修改成淘宝的源提升速度
移除原安装源
# gem sources --remove https://rubygems.org/
添加淘宝源
# gem sources -a http://ruby.taobao.org/
查看源的地址
# gem sources -l
安装Ruby on Rails
首先安装SQLite
# gem install sqlite3 --no-ri --no-rdoc
出现错误,错误信息
Fetching: sqlite3-1.3.8.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
       ERROR: Failed to build gem native extension.

   /usr/local/rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.
这是由于sqlite-devel没有安装,安装即可
安装rails
# gem install rails --no-ri --no-rdoc
查看rails版本
# rails -v
為了節省安裝時間可不安裝文件檔,這裡加上--no-ri跟--no-rdoc參數。
至此rails开发环境已结束!

文章标题:CentOS安装Ruby,Rails运行环境
文章起源:http://scyanting.com/article/pcocep.html