Sunday, April 14, 2013

Shell Script To Automate Ruby on Rails Installation on Mac OS X 10.8.3 Mountain Lion

When setting up a Ruby development environment on Mac OS X 10.8.3 I ran into plenty of errors and incompatibilities.  I wrote a shell script to automate the process.  Feel free to copy and paste the script below into a executable file to automate the roll out of Ruby on Mac OS X for your developers.  This script should be run with the user's login credentials.  Sudo or root are not needed.  

The script installs the following versions of software required to start writing Ruby on Rails code today!

Versions as of April 2013
  • Homebrew 0.9.4
  • RVM 1.19.5
  • Ruby 2.0.0p0 rev 39474
  • Rails 3.2.13
  • Git
  • MySQL 5.5.27
  • Xcode 4.6.1 and Xcode Command Line Tools (get it from the Apple Store for free)

Brew and RVM will also install all the dependencies you need.  Copy and paste everything between ---BEGIN--- and ---END---

# 04/2013
# Install Ruby latest stable
#   Homebrew
#   RVM
#   Rails
#   Git
#   MySQL
#   Don't forget Xcode command line tools

# Get install homebrew
ruby -e "$(curl -fsSkL"
brew install automake
echo "running 'brew doctor'..."
echo ""
brew doctor # Results must be clean to work properly
# Get Ruby stable version 2.0 as of 04/2013 1.9.3 also acceptable
\curl -L | bash -s stable --ruby
source ~/.rvm/scripts/rvm
# Update your .bashrc
grep -i rvm ~/.bashrc > /dev/null
if [ $? != 0 ]
echo "Updating .bashrc with source rvm line"
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc
echo "rvm already sourced in .bashrc"
# Get Rails
\curl -L | bash -s stable --rails --autolibs=enabled
# Get git
brew install git
# Get mysql
brew install mysql
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/mysql/5.5.27/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
# Reload/reset rvm env
rvm reload
# Get configs
echo "Get Configs and versions..."
brew --config
echo "-------------------------------------"
rvm --config
echo "-------------------------------------"
rails -v
echo "-------------------------------------"
ruby -v
echo "-------------------------------------"
git --version
echo "-------------------------------------"
# Done

No comments:

Post a Comment