Skip to content

OSX Installation Guide

morrowdavidson edited this page Feb 16, 2019 · 20 revisions

This guide assumes that you have already installed homebrew and Ruby on Rails.

Installing Postgresql:

before installing postgres make sure that homebrew is up to date

$ brew update
$ brew doctor

Now install postgresql

$ brew install postgresql

Initalize a new database once brew install is finished.

$ initdb /usr/local/var/postgres

Install lunchy to start and stop your postgres databases easily from the command line:

$ gem install lunchy

The commands for starting and stopping postgresql with lunchy are:

$ lunchy start postgres
$ lunchy stop postgres

If you run into a issue such as No daemon found matching 'postgres' at this point you can use Postgres.app instead of lunchy to get postgres set up and running on OSX.

create a new database for the odin project site:

$ createdb theodinproject

Thats it for postgresql, next we will install all of the gems that are needed.

Installing Gems and Migrating the Database

change into the project directory

$ cd theodinproject

run bundle install

$ bundle install

If a error occurs with the capybara gem install run this command to fix:

$ brew install qt

Once bundle has finished installing everything its time to get the database set up.

create the database and migrate it

$ rake db:create:all
$ rake db:migrate

create the test database

$ rake db:test:prepare

Get a Github API Token

You will need a Github API token to get all the tests to pass and for getting all the lesson content.

Go to personal access tokens in your Github user account settings and click the "generate new token" button. This will bring you to a new page. Give your token a description in the box provided, Something like "Odin " will do. Once that is done click the "generate token" button at the bottom of the page. The token highlighted in green is your new Github API token.

Copy your Github API token and create .env.local file in your local Odin Project directory. Paste your API token in place of <your api token here> like the example below:

GITHUB_API_TOKEN: <your api token here>

This Github API Token is used when updating the curriculum. Without it you may encounter rate-limiting errors.

Get a Mailchimp API Key and List ID

Mailchimp integration is setup to add newly registered users to a specified mailing list. This is done via the Mailchimp API and gem Gibbon. In order to enable this functionality in your local development and test environments you'll need to:

Finally, you need to add the API key and list ID to your .env.local:

MAILCHIMP_API_KEY: <your api key here>
MAILCHIMP_LIST_ID: <your list id here>

Run the Tests

You can now run all the tests, they should all be green

To run the rspec unit tests:

$ rspec

Seeding the Database and Populating the Lesson content

Next you need to seed the database with the course and lesson data.

$ rails db:seed

We pull in the lesson content from the Odin curriculum repository on Github. We have created a rake task to do this easily.

$ rake curriculum:update_content

Running the app locally

You can now run the app on your local machine.

start the server $ rails server

Go to the app in your browser: http://localhost:3000

Setting up Github Omniauth (Optional)

We allow users to create an account on the site with Github OAuth. To get this feature working locally follow the instructions in this section.

Go to OAuth Applications in your Github user account settings and click the "register a new application" button.

Fill in the form fields with the following:

Application Name odin

Homepage URL http://localhost:3000

Application Description the odin project

Authorization callback URL http://localhost:3000/users/auth/github/callback

Click the "Register application" button. This will display your Client ID and Client Secret which is what you will use to get OAuth working on your local machine.

Go to .env.local in your local project directory for The Odin Project and fill in the following:

GITHUB_API_TOKEN: <your api token here>
GITHUB_APP_ID: <your client ID here>
GITHUB_SECRET: <your client secret here>

To test all this is working correctly, run the app locally and try to sign up with Github.

Setting up Google OAuth (Optional)

We also allow users to create an account on the site with Google OAuth. To get this feature working locally follow the instructions in this section.

Visit the Google API Console to obtain OAuth credentials and agree to terms of service.

  1. Click "Select a Project" drop down

  2. Click "New Project" button on top right

    1. Set project name to odin

    2. Location can be default No Organization

    3. Click "Create" button

  3. Click "Credentials" in left nav.

    1. Navigate to "OAuth Consent Screen" on top nav.

      1. Set Application name odin

      2. Scroll to bottom and click "Save" button

  4. Click "Create Credentials" drop down

    1. Select "OAuth Client ID"

    2. Select "Web Application" for Application type

    3. Fill in the form fields with the following:

      1. Name: odin

      2. Authorized Javascript Origins: http://localhost:3000 make sure to press Enter to add it

      3. Authorized redirects URIs: http://localhost:3000/users/auth/google/callback make sure to press Enter to add it

      4. Click "Create" button. This will display your Client ID and Client Secret which is what you will use to get OAuth working on your local machine.

  5. Go to .env.local in your local project directory for The Odin Project and fill in the following:

    GOOGLE_CLIENT_ID: <your client ID here>
    GOOGLE_CLIENT_SECRET: <your client secret here>
    

To test all this is working correctly, run the app locally and try to sign up with Google.

Need Help?

If you have any problems getting anything set up in this guide please let us know in our Admin room in Discord