歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS安裝Ruby,Rails運行環境

CentOS安裝Ruby,Rails運行環境

日期:2017/2/28 14:36:12   编辑:Linux教程

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開發環境已結束!

Copyright © Linux教程網 All Rights Reserved