Tested on Yosemite. Should work on El Cap. Message me if it doesn't.
- You are tired of using vagrant
- You want to run guard
- You want use Sublime plugins (like RSpec or Guard plugins)
- You want your code to run faster in development
Brew aka Homebrew is a package management system for Mac OSX. You can think of it as a command line version of the App Store.
Open up the Mac Terminal and run this command to install brew on your mac:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After brew is done installing run
brew update
GNU File, Shell, and Text utilities needed to compile gems.
brew install coreutils
Open a terminal window. Run this command to download an install rvm and the latest version of ruby.
\curl -sSL https://get.rvm.io | bash -s stable --ruby
In the latest version of ruby you might see this error: "Empty path passed to certificates update, functions stack". There is a bug in rvm. Run rvm reinstall 2.5.0 --disable-binary
.
Close the current terminal window and open a new one.
rvm list # shows you all the versions of ruby installed on your computer
rvm -h # shows you the help menu with all the commands you can run
# Install ruby version 2.5.0
rvm install 2.5.0
# this will take a while... rvm is downloading and installing ruby
# Tell rvm to use 2.5.0 as the default version of ruby
rvm --default use 2.5.0
# Check that you are using the latest version of ruby
ruby -v
# Should show ruby 2.5.0
Install rails on your system so you can create new rails projects.
gem install rails
And now we can verify Rails is installed:
rails -v
# Rails 4.1.1
Install the server
brew install postgresql
Initialize the database
initdb /usr/local/var/postgres -E utf8
Get postgres to start automatically when your computer starts.
First, figure out which version of postgres was installed by brew.
cd /usr/local/Cellar/postgresql/
ls
# There should be a folder in here with the version number
Then, run the code below, replacing 9.2.1
with your version of postgresql.
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.2.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Source: http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/
gem install pg
Note: This might fail. If it does, ask a TA or add a comment to this gist.
The nokogiri gem needs these. See here for details: http://jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks/
xcode-select --install
Follow these instructions: http://stackoverflow.com/questions/23260748/manual-install-of-xcode-command-line-tools-not-working
- Open XCode
- Click on Xcode > Open Developer Tools > More Developers Tools This will take you to the Downloads for Apple Developers web site. Use your AppStore Id to login.
- Download Command Line Tools for your Mac OS X version. (Probably Mavericks April / March 2014).
Update Mar 2018: If the above instructions fail follow the instructions here, which should be up to date: https://stackoverflow.com/questions/9329243/xcode-install-command-line-tools
Run the terminal command below. It should successfully install the nokogiri gem (an DOM parsing library).
gem install nokogiri
cd /Users/monica/lighthouse/laser_shark
bundle install
Follow the other setup instructions for that rails app. For laser_shark
, you will have to edit your /etc/hosts
, for example.
You will need to update the database connection settings for all your Rails applications. In config/database.yml, make sure you have the following settings for the development and test environments. Of course, replace rotten_mangoes with the name of your rails app.
development:
adapter: postgresql
database: rotten_mangoes_development
host: localhost
encoding: unicode
test:
adapter: postgresql
database: rotten_mangoes_test
host: localhost
encoding: unicode
To check if the database connection settings work, see if you can create the database.
bin/rake db:create
If you see this error, make sure Postgres database is started.
SYS:laser_shark SYS$ bin/rake db:create
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
/Users/SYS/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `initialize'
You probably have XCode 5.1.1 or higher and tried to install the command line tools via command line. See Install the command line developer tools section above.
I wrote this down from memory. If any of the steps here don't work, please fork this gist, fix the issue and share with the class.
Thanks @kweestian. Updated the gist.