LoginSignup
3
2

More than 3 years have passed since last update.

CentOSにRuby on Rails開発環境を構築する方法(CentOS7.6 Ruby2.6.3 Rails 5.2.3)

Last updated at Posted at 2019-07-15

sudoersにユーザー登録

$ su

$ visudo
Allows people in group wheel to run all commands 
%wheel  ALL=(ALL)  ALL    #この行のコメントをはずす

ユーザをwheelグループに追加

$ usermod -G wheel username   

ユーザ切り替え

$ su username  

参考サイト

一般ユーザでsudoが実行できない場合

GitとRubyのビルドに必要なものをインストール

$ sudo yum update

$ sudo yum install -y git

$ sudo yum install -y bzip2 gcc openssl-devel readline-devel zlib-devel

rbenvのインストール

$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv

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

~/.bashrc(または~/.bash_profile)に以下を追記する。

# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

反映させ、確認する。

$ source ~/.bashrc

$ rbenv -v
>rbenv 1.1.2-2-g4e92322   # バージョンが表示される。

Rubyのインストール

Rubyのインストール可能なバージョンを確認する。

$ rbenv install --list 
>Available versions:
  1.8.5-p52
  1.8.5-p113
  1.8.5-p114
  1.8.5-p115
   .....
   .....

任意のバージョンのRubyをインストールする。

$ rbenv install 2.6.3

インストールしたバージョンを指定

$ rbenv global 2.6.3

$ ruby -v
>ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

Rails環境の作成

bundlerをインストール

$ gem install bundler

Railsの利用可能なバージョンを確認する

$ gem query -ra -n  "^rails$"

カレントディレクトリにGemfileを作成

$ bundle init

任意のバージョンを指定


$ echo 'gem "rails", "5.2.3"' >> Gemfile

./vendor/bundleにRails関連のGemが入る


$ bundle install --path vendor/bundle

bundle execの省略設定

スクリプトをダウンロード

$ curl -L https://github.com/gma/bundler-exec/raw/master/bundler-exec.sh > ~/.bundler-exec.sh

~/.bundler-exec.shを編集する

.....
.....
unicorn
unicorn_rails
wagon
rails   #railsを追記する
}"

define-bundler-aliases

unset -f define-bundler-aliases

~/.bashrc(または~/.bash_profile)に以下を追記する

# "bundle exec" shortcut setting
[ -f ~/.bundler-exec.sh ] && source ~/.bundler-exec.sh

反映する

$ source ~/.bashrc

SQLiteをインストール

$ sudo yum install sqlite-devel 

$ bundle install

参考サイト

CentOS7にRubyとRuby on Rails環境構築
bundle execを省略してみる

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