LoginSignup
3
4

More than 3 years have passed since last update.

centOS上でrails環境を作る【個人めも】

Last updated at Posted at 2018-10-27

目的

mac の上でもいいんだけど、チーム開発になると環境合わせるためにcentOSの上で開発する場合は多い。
centOS上でrails のプロジェクトを作ってhello ruby on rails を表示するまでを主に自分のために整理しておく。

centOSの環境はどうするんだって話ですが、最終的にはdockerでcentOSをゲストOSにしてその上で開発する環境を作りたいってのが背景だったので、dockerで作りました。

それに関する記事は別で書く予定

手順

必要なライブラリなどインストール

以下を順に実行した。
こいつらは全部Dockerfileの中に書いてしまってもいいかもしれない。
今はdocker execで中に入った後にbash スクリプトでインストールしている。

rbenv (ruby の管理)

sudo yum -y remove ruby
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
mkdir -p ~/.rbenv/plugins
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
cd ~/.rbenv/plugins/ruby-build
sudo ./install.sh
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

ruby

ここでは2.4.0のバージョンを入れた

yum install -y readline-devel
rbenv install 2.4.0
rbenv rehash
rbenv global 2.4.0
source ~/.bash_profile

rails

5.0.7を入れた

rbenv exec gem install rails -v 5.0.7
rbenv rehash
source ~/.bash_profile

MySQL

5.6がいいと思う

# デフォルトのDB削除
yum remove mariadb-libs
rm -rf /var/lib/mysql/

sudo yum install mysql-devel
sudo yum install mysql-server

mysql5.6のインストール↓
https://qiita.com/Esfahan/items/83200c64de8d826677b5

node入れる

入れないとrails sが失敗する。
nvmよりnodebrewがいいんじゃないかな。

curl -L git.io/nodebrew | perl - setup
echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
nodebrew install-binary v11.0.0
nodebrew install v11.0.0
nodebrew use v11.0.0
source ~/.bash_profile

rails プロジェクト作る

素晴らしい記事があった。わかりやすい!↓
https://qiita.com/yuitnnn/items/b45bba658d86eabdbb26

bundle exec rails new . -B -d mysql --skip-test
でプロジェクト作成した。

データベース作成

データベースをMySQLにしたので
これやらないと作らないとサーバ立たない
bundle exec rake db:create

rails server 立てる

ここで意気揚々とrails sしたら

mysqlソケットエラーが出た。ここで解決↓

sudo /etc/init.d/mysqld restart

めでたくhello画面でた

3
4
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
3
4