Ruby是Web开发和Linux管理的理想语言. Ruby提供了以前讨论的所有语言中的许多好处:PHP,Python和Perl.
要安装Ruby,最好通过 rbenv 进行引导.允许管理员轻松安装和管理Ruby环境.
安装Ruby的另一种方法是Ruby的标准CentOS包.建议使用 rbenv 方法及其所有好处.对于非Ruby精明的人来说,CentOS软件包会更容易.
首先,让我们为rbenv安装程序获取一些必需的依赖项.
git-core
zlib
zlib-devel
gcc-c ++
patch
readline
readline-devel
libyaml -devel
libffi-devel
openssl-devel
make
bzzip2
autoconf
automake
libtool
野牛
curl
sqlite-devel
其中大部分安装CentOS时,可能已经安装了软件包,具体取决于所选的选项和角色.安装我们不确定的所有内容是件好事,因为这可以减少安装需要依赖的软件包时的麻烦.
[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
方法1:动态Ruby开发环境的rbenv
现在作为将使用 Ruby 的用户 :
[rdc @ CentOS~] $ git clone https://img01.yuandaxia.cn/Content/img/tutorials/linux_admin/rbenv [rdc @ CentOS~ ] $ https://img01.yuandaxia.cn/Content/img/tutorials/linux_admin/ruby-build
ruby-build将为 rbenv :
注意:在运行install.sh之前,我们需要切换到root用户或管理用户。
[rdc@CentOS ruby-build]$ cd ~/ruby-build[rdc@CentOS ruby-build]# ./install.sh
让我们为rbenv设置外壳,并确保我们安装了正确的选项。
[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[ ]
一些有用的rbenv命令是:
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 :
[rdc@CentOS bin]$ ~/rbenv/bin/rbenv install -v 2.2.1
编译完成后:
[rdc@CentOS ~]$ ./ruby -v ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux] [rdc@CentOS ~]$
现在,我们有了一个可以正常工作的Ruby环境,其中包含Ruby 2.X分支的更新和有效版本。
Method 2 : Install Ruby from CentOS Packages
这是最简单的方法。 但是,它可能受到CentOS打包的版本和gems的限制。 对于认真的开发工作,强烈建议使用rbenv方法安装Ruby。
安装Ruby,所需的开发包和一些常用的gem。
[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
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]#