centos配置ruby开发环境(转 )

转自http://my.oschina.net/u/1449160/blog/260764
 
1. 安装ruby
1.1 yum安装,版本旧
#yum install ruby ruby-devel ruby-ri ruby-rdoc ruby-irb ruby-shadow zlib-devel openssl-devel curl-devel
1.2 删除
#yum remove ruby ruby-devel -y
1.3 源码安装
#wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz
#tar zxvf ruby-2.1.1.tar.gz
#cd ruby-2.1.1
#./configure --prefix=/usr/local/ruby --with-opessl-dir=/root/soft/openssl-1.0.0l
#make && make install
#echo "export PATH=/usr/local/ruby/bin:$PATH >> /root/.bash_profile"  (这条命令只对当前shell有效,要永久有效,请按下面到操作执行。指定系统运行ruby的环境变量,执行这行命令后,系统自带到会忽略掉,系统使用我们现在安装到ruby1.8.7版本)
--------------------------------------------------------------------------------------------

使其在全局局中都起作用:

就把export PATH=/usr/local/ruby/bin:$PATH 添加到系统到全局变量到文件中

打开文件 #vi /etc/profile

添加这行代码到文件中: export PATH=/usr/local/ruby/bin:$PATH(位于export PATH USER...这行下)

#source /etc/profile 

--------------------------------------------------------------------------------------------
#source /root/.bash_profile
#ruby --version
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
 
2.安装gem并更新gem源
2.1 如果存在更新为最新的RubyGems,
#gem update --system
如果版本过旧,
#gem install rubygems-update
#update_rubygems 
2.2 源码安装
#wget http://production.cf.rubygems.org/rubygems/rubygems-2.2.2.tgz
#tar zxvf rubygems-2.2.2.tgz
#cd rubygems-2.2.2
#ruby setup.rb
#gem --version
2.3 更换gem源为淘宝
#gem sources --remove https://rubygems.org/
#gem sources -a https://ruby.taobao.org/
#gem sources -l
*** CURRENT SOURCES ***
 
https://ruby.taobao.org/
如果是用Bundle(Rails 项目)
#source 'https://ruby.taobao.org/'
#gem 'rails', '4.1.0'
附:gem sources -a https://ruby.taobao.org/报错
ERROR:  While executing gem ... (Gem::Exception)
    Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
需要指定openssl目录(源码)。
 
3. 测试安装Mongodb driver for ruby
# gem install bson
# gem install bson_ext
# gem install mongo
# gem list --local
...
bson (2.2.21.10.0)
bson_ext (1.10.0)
...
mongo (1.10.0)
# irb
irb(main):001:0> require 'mongo'
=> true
posted on 2015-01-13 12:20  naughtyboy  阅读(562)  评论(0编辑  收藏  举报