LoginSignup
49
50

More than 5 years have passed since last update.

Centosにrails環境を構築

Last updated at Posted at 2013-08-06

gitのインストール

$ sudo yum install git

rbenvのインストール

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ exec $SHELL
$ rbenv
rbenv 0.4.0-51-ga2adc61
Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List all Ruby versions available to rbenv
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme

ruby-buildのインストール

git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

rubyのインストール

$ rbenv install 2.1.0
$ rbenv rehash
$ rbenv global 2.1.0

rubyのインストールで以下のようなエラーが出る場合も

$ rbenv install 2.1.0
Downloading yaml-0.1.6.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/5fe00cda18ca5daeb43762b80c38e06e
Installing yaml-0.1.6...
Installed yaml-0.1.6 to /home/vagrant/.rbenv/versions/2.1.0

Downloading ruby-2.1.0.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/9e6386d53f5200a3e7069107405b93f7
Installing ruby-2.1.0...

BUILD FAILED

Inspect or clean up the working tree at /tmp/ruby-build.20140427141801.13743
Results logged to /tmp/ruby-build.20140427141801.13743.log

Last 10 log lines:
                              io-console 0.4.2
                              json 1.8.1
                              minitest 4.7.5
                              psych 2.0.2
                              rake 10.1.0
                              rdoc 4.1.0
                              test-unit 2.1.0.0
installing rdoc:              /home/vagrant/.rbenv/versions/2.1.0/share/ri/2.1.0/system
installing capi-docs:         /home/vagrant/.rbenv/versions/2.1.0/share/doc/ruby
The Ruby openssl extension was not compiled. Missing the OpenSSL lib?

上のようなエラーが出た場合、以下を実行

$ sudo yum -y install openssl-devel

RDocのインストール

$ gem install rdoc

Ruby on Railsのインストール

$ gem install rails
$ rbenv rehash
$ rails -v

bundlerをインストール

$ gem install bundler

mysqlのインストール

$ sudo yum install http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
$ sudo yum install -y mysql-server mysql-devel 

#sqlサーバーの起動と自動起動
$ sudo service mysqld start
$ sudo chkconfig mysqld on

$ mysql -u root -p
mysql> GRANT ALL PRIVILEGES ON *.* to 'rails'@'localhost' IDENTIFIED BY 'password';

ローカルユーザーの作成
権限の変更

railsアプリの作成

#DBにMySQLを使う場合
$ rails new sample -d mysql
$ cd sample

javascriptの有効化

vi Gemfile
gem 'therubyracer', :platforms => :rubyをコメントイン
bundle install

ホストからゲストへのアクセス

#WEBric起動
$ rails s

http://ゲストのipアドレス:3000
アクセスできなければ、ファイアーウォールの設定を変更

$ sudo /etc/rc.d/init.d/iptables stop
#あるいは
$ sudo chkconfig iptables off

#これで確認、offならok
$ chkconfig --list iptables

再度、http://ゲストのipアドレス:3000 にアクセス

49
50
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
49
50