Linux-admin-configure-ruby-on-centos-linux
CentOS LinuxでRubyを構成する
Rubyは、Web開発とLinux管理の両方に最適な言語です。 Rubyは、前述のすべての言語(PHP、Python、Perl)で見られる多くの利点を提供します。
Rubyをインストールするには、管理者がRuby環境を簡単にインストールして管理できるようにする_rbenv_を使用してブートストラップするのが最適です。
Rubyをインストールするもう1つの方法は、Rubyの標準CentOSパッケージです。 _rbenv_メソッドをすべての利点とともに使用することをお勧めします。 CentOSパッケージは、Rubyに詳しくない人にとっては簡単です。
まず、rbenvインストーラーに必要な依存関係を取得しましょう。
- git-core
- zlib
- zlib-devel
- gcc-c ++
- パッチ
- 読み込まれた行
- readline-devel
- libyaml-devel
- libffi-devel
- openssl-devel
- make
- bzzip2
- autoconf
- オートメイク
- 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://github.com/rbenv/rbenv.git
[rdc@CentOS ~]$ https://github.com/rbenv/ruby-build.git
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 <command> [<args>]
いくつかの便利な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 2.Xブランチの更新された動作バージョンを備えた動作するRuby環境があります。
方法2:CentOSパッケージからRubyをインストールする
これが最も簡単な方法です。 ただし、CentOSからパッケージ化されたバージョンとgemによって制限される場合があります。 深刻な開発作業のために、_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
残念ながら、Rubyのやや古いバージョンが残っています。
[root@CentOS rdc]# ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
[root@CentOS rdc]#