Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

Setting up your development environment

Johan Henkens edited this page Jun 25, 2014 · 34 revisions

Here is a basic walkthrough on how to set up your development on an ubuntu precise (12.04) 32bit machine. The basic RVM info was taken from the Rails Tutorial Book.

Basic package requirements

$ sudo apt-get update && sudo apt-get upgrade 
$ sudo apt-get install \
openjdk-7-jre ruby1.9.3 git-core curl nodejs postgresql-9.1 \
postgresql-server-dev-9.1

Postgresql setup

It is recommended that we use the same database for development as we will use for production. Postgresql is well regarded, and is the current plan for our database. If using Mac, follow the instructions here but replace the username 'blog' with octopi. For ubuntu 12.04, follow the steps below (hints were modified from a StackOverflow post):

Set up a user for your ubuntu login

$ sudo su postgres -c psql
postgres=# CREATE ROLE <username> SUPERUSER LOGIN;
postgres=# \q

Change unix-socket based (local) logins to be trusting (don't check user auths)

$ sudo sed -i -e 's/^\(local\s*all\s*all\s*\)peer/\1trust/' /etc/postgresql/9.1/main/pg_hba.conf
$ sudo service postgresql restart

Create your personal db so we can login

$ createdb

Log in to postgres and create an octopi user and change some database encoding settings

You will have to enter the following commands, isolated here for copy/paste ease.

CREATE USER octopi CREATEDB;
update pg_database set datistemplate=false where datname='template1';
drop database Template1;
create database template1 with owner=postgres encoding='UTF-8'
  lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
 
update pg_database set datistemplate=true where datname='template1';
$ psql
vagrant=# CREATE USER octopi CREATEDB;
CREATE ROLE
vagrant=# update pg_database set datistemplate=false where datname='template1';
UPDATE 1
vagrant=# drop database Template1;
DROP DATABASE
vagrant=# create database template1 with owner=postgres encoding='UTF-8'
vagrant-#   lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
CREATE DATABASE
vagrant=#
vagrant=# update pg_database set datistemplate=true where datname='template1';
UPDATE 1
vagrant=# \q

RVM Setup

I have the project configured to use ruby 2.0.0 and use rvm to manage a gemset. If you use a different gemset manager, you can ignore this and try to get it running with your own manager. Remember, do not run the RVM setup as root - it should be a user-level install.

$ curl -sSL https://get.rvm.io | bash -s stable
$ source ~/.bash_profile

Right now, you should go through and edit your ~/.bash* and ~/.zsh* files if you desire, since rvm appends stuff to them.

Next we will install the requirements to build ruby, and then install ruby, and finally create a new gemset for us to use.

$ rvm requirements
$ rvm install 2.0.0
$ rvm use 2.0.0@octopi-webapp --create

Now we need to do one more thing. Open ~/.bash_profile in terminal and add the following two lines:

source ~/.profile
source ~/.bashrc

This fixes an issue with RVM that happens when the terminal can't recognize RVM. Source

Now you can go ahead and clone octopi-webapp using whichever method you like best. When you cd into the octopi-webapp folder, you should be greeted with:

You are using '.rvmrc', it requires trusting, it is slower and it is not compatible with other ruby managers,
you can switch to '.ruby-version' using 'rvm rvmrc to [.]ruby-version'
or ignore this warning with 'rvm rvmrc warning ignore /home/vagrant/octopi-webapp/.rvmrc',
'.rvmrc' will continue to be the default project file in RVM 1 and RVM 2,
to ignore the warning for all files run 'rvm rvmrc warning ignore all.rvmrcs'.

********************************************************************************************************************
* NOTICE                                                                                                           *
********************************************************************************************************************
* RVM has encountered a new or modified .rvmrc file in the current directory, this is a shell script and           *
* therefore may contain any shell commands.                                                                        *
*                                                                                                                  *
* Examine the contents of this file carefully to be sure the contents are safe before trusting it!                 *
* Do you wish to trust '/home/vagrant/octopi-webapp/.rvmrc'?                                                       *
* Choose v[iew] below to view the contents                                                                         *
********************************************************************************************************************
y[es], n[o], v[iew], c[ancel]>

Go ahead and enter y for yes. The reason we are using a .rvmrc rather than other rvm files is because RubyMine likes .rvmrc files.

You can verify things are going well by the following:

$ rvm gemset list

gemsets for ruby-2.0.0-p451 (found in /home/vagrant/.rvm/gems/ruby-2.0.0-p451)
   (default)
   global
=> octopi-webapp

From this point, you should be able to install RubyMine via the website, open the octopi-webapp project, and have all the 'Tools | Bundler' options work just as if they were run in the command line.

Finish setup and get it all running

$ bundle install --without production
$ rake db:create
$ rake db:migrate
$ rails s

Now try and open localhost:3000 in your browser of choice.

Windows

PostgreSQL Bundler information for Windows

In order to get the pg gem to build on cygwin for windows you need to add the following command to your bash profile (or potentially just do it once before the first install). `export CONFIGURE_ARGS='with-pg-dir="/cygdrive/c/Program Files/PostgreSQL/9.3" with-pg-lib="/cygdrive/c/Program Files/PostgreSQL/9.3/lib"