Railsチュートリアルの開発環境構築部分だけをまとめました。
バージョンなどは2018/7/12時点の情報です。
環境構築する項目
- cloud9環境
- rails環境
- git環境(BitBucket)
- 本番用サーバ環境(heroku)
cloud9環境
ここは割愛
AWSに登録してcloud9環境を一つ作ってください。
一番安いプランでい胃と思います。
rails環境構築
$ gem install rails -v 5.1.4 #rails環境のインストール
$ rails _5.1.4_ new ***_app #アプリファイルの作成 ***は作りたいアプリ名
/***_app/Gemfile を以下に差し替え
source 'https://rubygems.org'
gem 'rails', '5.1.4'
gem 'puma', '3.9.1'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.7.0'
group :development, :test do
gem 'sqlite3', '1.3.13'
gem 'byebug', '9.0.6', platform: :mri
end
group :development do
gem 'web-console', '3.5.1'
gem 'listen', '3.1.5'
gem 'spring', '2.0.2'
gem 'spring-watcher-listen', '2.0.1'
end
group :production do
gem 'pg', '0.20.0'
end
# Windows環境ではtzinfo-dataというgemを含める必要があります
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
$ cd ***_app/ #アプリファイルに移動
$ bundle install --without production
#↓budle updateしろ!とエラーが出たら以下も実行
$ bundle update
git環境
まずGitHub or BitBucketにアカウント登録
秘密鍵の作成
$ cd ~/.ssh
$ ls #~/.ssh にid_rsa,id_rsa.pubがないことを確認
$ ssh-keygen #id_rsa,id_rsa.pubを作成
#鍵作成パス,パスワード,パスワード確認の順で入力を求められる
#鍵作成パスは空白(~/.sshに作られる) パスワードは任意の値を入力
$ ls #id_rsa,id_rsa.pubが存在している
$ cat ~/.ssh/id_rsa.pub #上記をコピーしてbitbucket,githubに登録
git設定
$ cd /***_app
$ git init
$ git config --global user.name "Your Name"
$ git config --global user.email you@example.com
$ git add -A
$ git commit -m "first commit"
#githubでリポジトリ作成
$ cd ~/environment/***_app/
$ git remote add origin git@bitbucket.org:<ユーザ名>/<リポジトリ名>.git
$ git push -u origin --all
本番サーバ環境(heroku)
#herokuアカウント作成
$ heroku --version #インストールされていないことの確認
$ source <(curl -sL https://cdn.learnenough.com/heroku_install) #herokuインストール
$ heroku --version #インストールされている
$ heroku login #herokuの登録e-mail、パスワードを求められるので入力
$ heroku keys:add #sshkeyの登録 Yを入力
$ heroku create #herokuサーバ作成
$ git push heroku master #herokuサーバにpush
完了
以上で環境構築は終了
テスト,BootStrapの設定等はお好みで