raotanの備忘録

個人的備忘録

Ruby on Rails チュートリアルの為の環境構築

Ruby on Railsチュートリアルを進める為に環境構築をしてみる 

 

cURLコマンドをインストール

$ sudo apt-get install curl

RVMをインストール

$ \curl -sSL https://get.rvm.io | bash -s stable
$ source ~/.profile

RubyRailsをインストール

$ \curl -sSL https://get.rvm.io | bash -s stable
$ rvm install ruby-2.1.2 --default
$ source ~/.bash_profile
$ gem install rails

Ruby Newしてみる

$ cd
$ mkdir rails_projects
$ cd rails_projects
$ rails new first_app
$ cd first_app

ここで実行しようとすると・・・

$ rails server
/home/hoge/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /home/nobu/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs.rb:5:in `<module:ExecJS>'
:

なんか凄い勢いで怒られますわ・・・で

$ subl Gemfile

Gemfile開いて以下の2行を追加してからgemを再インストール

gem 'execjs'
gem 'therubyracer'
$ bundle update
$ bundle install
# 再チャレンジ
$ rails server
# ターミナルをもいっこ開いて
$ google-chrome http://localhost:3000/

無事にアプリケーションにアクセスできました。

f:id:raotan:20140810125809p:plain

 

つづいてGitをインストール

$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
$ apt-get install git

# セットアップ
$ git config --global user.name "あなたの名前"
$ git config --global user.email your.email@example.com

# 先程作ったRailsアプリケーションのルートディレリに移動して
$ git ini

# Gitにファイルを追加
$ git add .

# commit
$ git commit -m "Initialize repository"

# アプリケーションをpush
$ git remote add origin https://github.com/<username>/first_app.git
$ git push -u origin master

ここを参考にGitHubのSSHキーを作成して設定しておく

Heroku Toolもインストールしておく

$ wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh

Herokuに空アプリをデプロイしてみる

$ heroku login
$ heroku create

# herokuにリポジトリをpush
$ git push heroku master
$ heroku open

f:id:raotan:20140810174644p:plain