天天看點

在CentOS & RHEL環境中使用RVM安裝Ruby 2.1.8安裝依賴包 安裝RVM安裝RVM環境安裝Ruby設定預設Ruby版本檢查目前Ruby版本

Ruby 是一種動态,面向對象的程式設計語言。在Linux平台使用RVM(Ruby版本管理器)安裝Ruby将會更加容易。RVM的另一個好處是可以毫無沖突地管理不同版本的Ruby,僅适用于' rvm use'指令即可。

本文将介紹如何在CentOS, RedHat 系統上使用RVM安裝Ruby 2.1.8 。如果安裝其他版本請參照下面的連結。

Previous stable: Ruby 2.0.0

Old stable: Ruby 1.9.3

安裝依賴包

首先我們需要使用下面指令安裝Ruby安裝所需要的依賴包。

# yum install gcc-c++ patch readline readline-devel zlib zlib-devel 
# yum install libyaml-devel libffi-devel openssl-devel make 
# yum install bzip2 autoconf automake libtool bison iconv-devel sqlite-devel
           

安裝RVM

使用下面的指令安裝最新的穩定版本的RVM。下面的指令會自動安裝全部依賴包。

# curl -L get.rvm.io | bash -s stable
           

安裝RVM環境

RVM提供了一個腳本來用來在安裝Ruby前設定好系統環境 。使用下面的指令來設定rvm環境。

# source /etc/profile.d/rvm.sh
           

安裝Ruby

在完成設定RVM環境後,使用下面指令安裝Ruby。

# rvm install 2.1.8
           

[Sample Output]

Searching for binary rubies, this might take some time.
No binary rubies available for: centos/7/x86_64/ruby-2.1.8.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.1.8, this may take a while depending on your cpu(s)...
ruby-2.1.8 - #downloading ruby-2.1.8, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 11.4M  100 11.4M    0     0  33.5M      0 --:--:-- --:--:-- --:--:-- 33.6M
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.1.8 - #extracting ruby-2.1.8 to /usr/local/rvm/src/ruby-2.1.8....
ruby-2.1.8 - #configuring.....................................................
ruby-2.1.8 - #post-configuration..
ruby-2.1.8 - #compiling.........................................................................................................
ruby-2.1.8 - #installing.................................
ruby-2.1.8 - #making binaries executable..
ruby-2.1.8 - #downloading rubygems-2.4.8
ruby-2.1.8 - #extracting rubygems-2.4.8.....
ruby-2.1.8 - #removing old rubygems.........
ruby-2.1.8 - #installing rubygems-2.4.8......................
ruby-2.1.8 - #gemset created /usr/local/rvm/gems/[email protected]
ruby-2.1.8 - #importing gemset /usr/local/rvm/gemsets/global.gems...............................................
ruby-2.1.8 - #generating global wrappers........
ruby-2.1.8 - #gemset created /usr/local/rvm/gems/ruby-2.1.8
ruby-2.1.8 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.1.8 - #generating default wrappers........
ruby-2.1.8 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.1.8 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri
           

設定預設Ruby版本

使用rvm指令設定使用的預設ruby版本。

# rvm use 2.1.8 --default

Using /usr/local/rvm/gems/ruby-2.1.8
           

檢查目前Ruby版本

使用下面指令來檢查目前使用的Ruby版本

# ruby --version

ruby 2.1.8p440 (2015-12-16 revision 53160) [x86_64-linux]
           

至此Ruby成功安裝。

原文連結 http://tecadmin.net/install-ruby-2-1-on-centos-rhel/

繼續閱讀