开发手册 欢迎您!
软件开发者资料库

在CentOS Linux上配置Ruby

Linux管理员在CentOS Linux上配置Ruby - 从简单和简单的步骤学习Linux管理,从基本概念开始,包括CentOS概述,基本CentOS Linux命令,文件/文件夹管理,用户管理,配额管理,系统服务启动和停止,使用systemctl的资源管理,带有crgoups的资源管理,进程管理,防火墙设置,在CentOS Linux中配置PHP,使用CentOS Linux设置Python,在CentOS Linux上配置Ruby,为CentOS Linux设置Perl,安装和配置开放式LDAP,创建SSL证书,安装Apache Web服务器CentOS 7,在CentOS 7上安装MySQL,设置Postfix MTA和IMAP / POP3,安装匿名FTP,远程管理,CentOS中的流量监控,日志管理,备份和恢复,系统更新,Shell脚本,包管理,卷管理。

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命令是:

CommandsAction
localSets or shows the local application-specific Ruby version
globalSets or shows the global Ruby version
shellSets or shows the shell-specific Ruby version
installInstalls a Ruby version using ruby-build
uninstallUninstalls a specific Ruby version
rehashRehashes rbenv shims (run this after installing executables)
versionShows the current Ruby version and its origin
versionsLists all Ruby versions available to rbenv
whichDisplays the full path to an executable
whenceLists 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]#