Linux Admin 简明教程
Configure Ruby on CentOS Linux
Ruby 既适用于 Web 开发,又适用于 Linux 管理。Ruby 提供了前面讨论过的所有语言(PHP、Python 和 Perl)中的许多好处。
Ruby is a great language for both web development and Linux Administration. Ruby provides many benefits found in all the previous languages discussed: PHP, Python, and Perl.
若要安装 Ruby,最好通过 rbenv 引导,这允许管理员轻松安装和管理 Ruby 环境。
To install Ruby, it is best to bootstrap through the rbenv which allows the administrators to easily install and manage Ruby Environments.
安装 Ruby 的另一种方法是使用 Ruby 的标准 CentOS 软件包。建议使用 rbenv 方法及其所有好处。对于不了解 Ruby 的人来说,CentOS 软件包会更容易。
The other method for installing Ruby is the standard CentOS packages for Ruby. It is advisable to use the rbenv method with all its benefits. CentOS packages will be easier for the non-Ruby savvy.
首先,让我们为 rbenv 安装程序获取一些必需的依赖项。
First, let’s get some needed dependencies for rbenv installer.
-
git-core
-
zlib
-
zlib-devel
-
gcc-c++
-
patch
-
readline
-
readline-devel
-
libyaml-devel
-
libffi-devel
-
openssl-devel
-
make
-
bzzip2
-
autoconf
-
automake
-
libtool
-
bison
-
curl
-
sqlite-devel
根据安装 CentOS 时选择的选项和角色,这些软件包中的大多数可能已经安装。最好安装我们不确定的所有内容,因为这可以减少在安装需要依赖项的软件包时遇到的麻烦。
Most of these packages may already be installed depending on the chosen options and roles when installing CentOS. It is good to install everything we are unsure about as this can lead to less headache when installing packages requiring dependencies.
[root@CentOS]# yum -y install git-core zlib zlib-devel gcc-c++ patch readline
readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf
automake libtool bison curl sqlite-devel
Method 1 − rbenv for Dynamic Ruby Development Environments
现在,作为将要使用 Ruby 的用户:
Now as the user who will be using Ruby −
[rdc@CentOS ~]$ git clone https://github.com/rbenv/rbenv.git
[rdc@CentOS ~]$ https://github.com/rbenv/ruby-build.git
ruby-build 将为 rbenv 提供安装功能:
ruby-build will provide installation features to rbenv −
Note − 我们需要在运行 install.sh 之前切换到 root 或管理用户。
Note − We need to switch to root or an administration user before running install.sh
[rdc@CentOS ruby-build]$ cd ~/ruby-build
[rdc@CentOS ruby-build]# ./install.sh
让我们为 rbenv 配置 Shell,并确保已安装正确的选项。
Let’s set our shell for rbenv and assure we have installedthe correct options.
[rdc@CentOS ~]$ source ~/rbenv/rbenv.d/exec/gem-rehash.bash
[rdc@CentOS ruby-build]$ ~/rbenv/bin/rbenv
rbenv 1.1.0-2-g4f8925a
Usage: rbenv <command> [<args>]
一些有用的 rbenv 命令为:
Some useful rbenv commands are −
Commands |
Action |
local |
Sets or shows the local application-specific Ruby version |
global |
Sets or shows the global Ruby version |
shell |
Sets or shows the shell-specific Ruby version |
install |
Installs a Ruby version using ruby-build |
uninstall |
Uninstalls a specific Ruby version |
rehash |
Rehashes rbenv shims (run this after installing executables) |
version |
Shows the current Ruby version and its origin |
versions |
Lists all Ruby versions available to rbenv |
which |
Displays the full path to an executable |
whence |
Lists all Ruby versions that contain the given executable |
现在,我们安装 Ruby
Let’s now install Ruby −
[rdc@CentOS bin]$ ~/rbenv/bin/rbenv install -v 2.2.1
编译完成后
After compilation completes −
[rdc@CentOS ~]$ ./ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
[rdc@CentOS ~]$
现在,我们拥有一个工作 Ruby 环境,其 Ruby 2.X 分支为已更新且正常工作的版本。
We now have a working Ruby environment with an updated and working version of Ruby 2.X branch.
Method 2 − Install Ruby from CentOS Packages
这是最简单的方法。但是,它受 CentOS 中打包的版本和 gem 的限制。对于认真的开发工作,强烈建议使用 rbenv 方法来安装 Ruby。
This is the most simple method. However, it can be limited by the version and gems packaged from CentOS. For serious development work, it is highly recommended to use the rbenv method to install Ruby.
安装 Ruby、所需的开发包和一些常见的 gem。
Install Ruby, needed development packages, and some common gems.
[root@CentOS rdc]# yum install -y ruby.x86_64 ruby-devel.x86_64 ruby-
libs.x86_64 ruby-gem-json.x86_64 rubygem-rake.noarch
遗憾的是,我们使用的是过时的 Ruby 版本。
Unfortunately, we are left with somewhat outdated version of Ruby.
[root@CentOS rdc]# ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
[root@CentOS rdc]#