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版本)
使其在全局局中都起做用:linux
就把export PATH=/usr/local/ruby/bin:$PATH 添加到系統到全局變量到文件中shell
打開文件 #vi /etc/profileruby
添加這行代碼到文件中: export PATH=/usr/local/ruby/bin:$PATH(位於export PATH USER...這行下)bash
#source /etc/profile curl
#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
.
2
,
1
.
10
.
0
)
bson_ext (
1
.
10
.
0
)
...
mongo (
1
.
10
.
0
)
# irb
irb(main):
001
:
0
> require
'mongo'
=>
true