######tl;dr
$ curl -sSL https://get.rvm.io | bash -s stable && source ~/.rvm/scripts/rvm # Get latest Ruby using RVM
$ gem install rails # Get Rails
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # Get Homebrew
$ brew install postgresql # Get Postgresql
$ brew install git # Get Git--
Ruby on Rails is a popular framwork for building web apps, here's a quick guide to getting set up on Mac.
A more detailed explanation of the steps is available here.
###Ruby
Manage your Ruby installations with RVM – Ruby enVironment Manager.
$ curl -sSL https://get.rvm.io | bash -s stableThe dollar sign
$represents the prompt. You don't need to type it.
Restart Terminal before continuing.
Install ruby with RVM.
$ rvm install 2.1.3###Gems
RubyGems is a Ruby package manager. Ruby software packages are called Gems. Install the Rails gem with the gem command.
$ gem install rails###Rails
Rails comes with a script for generating boilerplate code. Use rails new every time you create a new project.
$ rails new ~/Sites/new_rails_app
$ cd ~/Sites/new_rails_app
$ rails serverThe rails server (also rails s) command runs the app and makes it available at the loopback address http://0.0.0.0:3000/.
You're now ready to build an awesome web app. Type the rails command without arguments to see what commands are available and check out the getting started guides.
###Homebrew
Homebrew is a package manager for OSX software. Use it to install Git and PostgreSQL.
Install Homebrew:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"You may need to ensure that /usr/local/bin appears before /usr/bin in yout $PATH variable.
The
$PATHvariable is a list of directories in which your computer looks when it's trying to execute a program from a Shell.
To check it does appear at the front:
$ echo $PATHIf it doesn't to make sure it does (in bash):
$ echo "PATH=\$PATH:/usr/local/bin" >> ~/.bashrc
$ source ~/.bashrcAm I running bash? Look at the top of the Terminal window or at the prompt:
Git is a powerful and popular tool for keeping track of changes to code.
$ brew install gitTo use Git:
$ git init # Initialises folder as Git repo
$ git add . # Adds all changes to the staging area
$ git commit -m 'Initial commit' # Commits the changes to Git with a messagePostgreSQL is database software. We need it for production databases for apps we want to host on Heroku.
$ brew install postgresqlTo use PostgreSQL as the database driver in Rails the pg Gem is needed. First wrapt the existing sqlite3 Gem reference in a block:
# ./Gemfile
group :development, :test do
gem 'sqlite3'
endThen specify gem pg for production:
# ./Gemfile
group :production do
gem 'pg'
end$ bundle installSet postgresql as the database driver for production:
production:
adapter: postgresql
encoding: unicode
database: app_name_production # replace app_name_ with the name of your app
username: app_name # replace app_name_ with the name of your app
password: <%= ENV['APP_NAME_DATABASE_PASSWORD'] %> # replace APP_NAME_ with the name of your appDeploying Rails to Heroku is as easy as downloading the toolbelt and using a couple of heroku commands.
$ heroku create
$ git push heroku master
$ heroku run rake db:migrate
$ heroku run rake db:seed
$ heroku openFor more a more detailed overview see this tutorial.
