Skip to content

Instantly share code, notes, and snippets.

@tadyjp
Last active January 2, 2016 06:49
Show Gist options
  • Save tadyjp/8266247 to your computer and use it in GitHub Desktop.
Save tadyjp/8266247 to your computer and use it in GitHub Desktop.
macにruby2.0と+rails4開発環境を一発で作るコマンド。 自己責任でお願いします。 使い方: $ ruby -e "$(curl -sSL https://gist.github.com/tadyjp/8266247/raw)"
# coding: utf-8
################################################################################
# 使い方
#
# 1. Xcodeから「Command Line Tool」をインストール
# 2. ターミナルを起動
# 3. 次の1行を入力してEnter
# ruby -e "$(curl -sSL https://gist.github.com/tadyjp/8266247/raw)"
# 4. 気長に待つ(30分ほど待つ)
#
################################################################################
require 'open3'
STDOUT.sync = true
INSTALLING_RUBY_VERSION = '2.0.0-p247'
INSTALLING_RAILS_VERSION = '4.0.0'
def exec_command(cmd)
stdin, stdout, stderr = Open3.popen3(cmd)
stdout_str = stdout.read
puts "*** [OUT] #{stdout_str}" if stdout_str.length > 0
stderr_str = stderr.read
puts "*** [ERROR] #{stderr_str}" if stderr_str.length > 0
end
puts <<EOF
###############################################################################
# Welcome to RailsMacKit by tady.
###############################################################################
EOF
puts ''
puts 'Installing homebrew...'
exec_command(%Q|ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"|)
puts ''
puts 'Updating homebrew...'
exec_command('brew update')
puts ''
puts 'Installing rbenv...'
exec_command('brew install rbenv')
puts ''
puts 'Installing ruby-build...'
exec_command('brew install ruby-build')
exec_command(%Q|echo 'eval "$(rbenv init -)"' >> ~/.bash_profile|)
exec_command(%Q|source ~/.bash_profile|)
puts ''
puts 'Rehashing rbenv...'
exec_command('rbenv rehash')
puts ''
puts "Installing ruby (#{INSTALLING_RUBY_VERSION})..."
exec_command("rbenv install #{INSTALLING_RUBY_VERSION}")
puts ''
puts 'Set ruby globally...'
exec_command("rbenv global #{INSTALLING_RUBY_VERSION}")
puts ''
puts 'Updating gem ...'
exec_command('gem update')
puts ''
puts 'Installing rails ...'
exec_command("gem install rails -v #{INSTALLING_RAILS_VERSION} --no-ri --no-rdoc")
exec_command("rbenv rehash")
exec_command(%Q|source ~/.bash_profile|)
puts ''
puts 'Checking rails version ...'
exec_command('rails -v')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment