davidteren
1/5/2018 - 4:46 PM

Mac OS X Rails Dev Environment Setup

Mac OS X Rails Dev Environment Setup

Mac OS X Rails Dev Environment Setup

Prerequisite: Be sure to have the latest Xcode installed before proceeding.

Install Homebrew

Homebrew is the defacto package manager on the OS X platform

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Mathias’s dotfiles

Sensible hacker defaults for macOS. More info

git clone https://github.com/mathiasbynens/dotfiles.git && cd dotfiles && source bootstrap.sh

Adds some great features like a bunch of really handy aliases. Some you can try yourself:

# To list all files including hidden, with forward-slash to denote folders.
la 
    
# To show hidden files in Finder
show

# To hide hidden files in Finder
hide

# To view all the aliases now available for your use
alias

Add the .extra as detailed here

Be sure to check the changes that the .macos scipt makes before using it to set some sensible macOS defaults. You may want to comment some out.

Setup Terminal

  • Open Preferences for the Terminal app.
  • Under Profiles select Import via the settings cog at the bottom of the pane.
  • From there, import the Solarized Dark xterm-256color.terminal profile.
  • Now select the imported profile in the list and make it the default by clicking the Default button at the bottom of the pane.
  • Restart the Terminal app for the new profile to be enabled.

Setup the Ruby & Rails Environments

  1. Install rbenv

    rbenv allows for easily installation and switching between various versions of Ruby. More

    Install rbenv.

    brew install rbenv      
    

    Set up rbenv integration with your shell.

    rbenv init
    

    Make rbenv load automatically.

    if ! grep -i 'eval "$(rbenv init -)"' ~/.bash_profile ; then echo 'eval "$(rbenv init -)"' >>  ~/.bash_profile ; fi
    

    Refresh the Terminal.

    reload 
    

    Check that rbenv is setup correctly

    curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
    

    You should get something like this.

  2. Install Ruby

    Install the version you require

    rbenv install 2.4.1
    

    Set the global Ruby version

    rbenv global 2.4.1
    

    Check that it's set

    ruby -v
    

    It should return the version you set.

  3. Install Bundler

    Bundler is a Gem manager.

    gem install bundler
    
  4. Set Gem docs generation exclusion.

    if ! grep -i 'gem: --no-ri --no-rdoc --no-document' ~/.gemrc ; then echo 'gem: --no-ri --no-rdoc --no-document' >>  ~/.gemrc ; fi
    
  5. Install Rails

    gem install rails
    

Setup Postgres

  1. Install Postgres.app

    Download from here , install, open and select Initialize

  2. Set the $PATHfor command line use.

    sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp && reload
    

Create Test Rails App

Here we will create simple blog app

# Create a project directory  
mkdir -p ~/Projects/RailsApps
cd ~/Projects/RailsApps

# Create a new app preconfiguring postgres as the database
rails new my_blog -d postgresql
cd my_blog

# Scaffold a Post MVC
rails generate scaffold Post title:string body:text
    
# Create the db & run migrations
rails db:create db:migrate

#Start the server
rails server

Check that the app is running at http://localhost:3000/

Check that you can create, edit & delete Posts http://localhost:3000/posts