Mac OS X Rails Dev Environment Setup
Prerequisite: Be sure to have the latest Xcode installed before proceeding.
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)"
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.
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.
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.
Install Bundler
gem install bundler
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
Install Rails
gem install rails
Install Postgres.app
Download from here , install, open and select Initialize
Set the $PATH
for command line use.
sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp && reload
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