LoginSignup
26
25

More than 5 years have passed since last update.

CentOSにRVMと最新版Ruby&Railsをインストールする

Last updated at Posted at 2012-12-26

2012年8月17日 クリーンインストールしたCentOSで検証。

1. 必要なライブラリのインストール

Railsや開発に必要なライブラリをインストールします。

$ sudo yum install -y git zlib-devel perl-ExtUtils-MakeMaker httpd httpd-devel openssl-devel libyaml-devel libxml2-devel libxslt-devel libffi-devel readline-devel pcre-devel iconv-devel sqlite-devel mysql mysql-server mysql-devel postgresql postgresql-server postgresql-devel curl-devel nkf

2. RVMのインストール

次にRVMをインストールします。
成功すると、ホームディレクトリに.rvmが置かれ、.bash_profileに.rvmへのパスが追記されます。

$ cd ~/
$ bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
$ ls -la

drwxrwxr-x  23 is0me test 4096  8月 16 16:52 2012 .rvm
[...]
.bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

.bash_profileを読み込み直し、rvmコマンドを使えるようにします。

.bash_profile
$ source ~/.bash_profile

3. Rubyのインストール

インストールしたRVMを使い、Rubyをインストールします。
まずは、最新版のバージョンを確認します。

$ rvm list known|grep 2.0.0

[ruby-]2.0.0-rc1
[ruby-]2.0.0-rc2
[ruby-]2.0.0[-p0]
rbx-2.0.0-rc1

最新版をインストールする場合は、

$ rvm install 2.0.0

バージョンを指定する場合は、以下のように入力しインストールします。

$ rvm install 2.0.0-rc1

インストール後、そのバージョンをデフォルトに設定しておきます。
RVMを使うことで複数のバージョンを使い分ける事が楽になります。
同時に、gemコマンドも使えるようになります。

$ rvm use 2.0.0 --default
Using /usr/local/rvm/gems/ruby-2.0.0-p0

$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]

$ gem -v
1.8.24

4. Ruby on Railsをインストール

最後にRailsのインストールです。

$ gem install rails 
$ rails -v

Rails 3.2.8

後々必要になるので、rakeもインストールすれば完了です。
rakeは、DBをマイグレーションするのに必要になります。

$ gem install rake

Apache上でRails3を動かす場合は、passengerをインストールしてください。
Apache上で、Rails3を動かす

26
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
25