Warning – Ruby 2.1 is reached to end of life and no more maintained. Kindly use below tutorials to install latest version of ruby
-
目前稳定—— 安装 Ruby 最新稳定版本
-
以前的稳定 – 安装 Ruby 以前的稳定版本
Ruby is a dynamic, object-oriented programming language.We are using RVM, which stands for Ruby Version Manager, which makes easier to install Ruby on Linux platform. RVM is also helpful for managing multiple version of Ruby without conflicting, and we can switch system to any version of Ruby using a single command.
This article will helps you to How to Install Ruby 2.1.8 on CentOS, RedHat Systems using RVM. To install other releases of Ruby use following links
第 1 步:安装所需的软件包
首先,我们需要使用以下命令在我们的系统上安装 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
第2步:安装RVM
使用以下命令在您的系统上安装最新稳定版本的 RVM。此命令将自动下载所有必需的文件并安装在您的系统上。
# curl -L get.rvm.io | bash -s stable
步骤3:设置RVM环境
RVM 提供了一个 shell 脚本来在安装 Ruby 之前设置系统环境。使用以下命令设置 rvm 环境。
# source /etc/profile.d/rvm.sh
第四步:安装红宝石
完成 RVM 环境的设置后,让我们使用以下命令安装 Ruby 语言。
# rvm install 2.1.8
[输出示例]
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/ruby-2.1.8@global
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
第 5 步:设置默认 Ruby 版本
使用 rvm 命令设置应用程序使用的默认 ruby 版本。
# rvm use 2.1.8 --default
Using /usr/local/rvm/gems/ruby-2.1.8
第 6 步:检查当前 Ruby 版本。
使用以下命令可以检查当前使用的 ruby 版本。
# ruby --version
ruby 2.1.8p440 (2015-12-16 revision 53160) [x86_64-linux]
恭喜您已在系统上成功安装 Ruby。阅读我们的下一篇文章将 Ruby 与 Apache 集成网络服务器,步骤简单。
参考:
1. http://rvm.io/rubies/installing