Docs on how to set up an OSX machine for web development, with an emphasis on Python/Django
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.rst

README.rst

Configuring macOS for Development

This is Green Light Go's official guide for developers on how to install the most commonly used software for our projects.

This guide assumes you are doing a clean install of Homebrew on a clean install of macOS.

Homebrew

Install:

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

Git

Install the latest version instead of using the older macOS supplied version:

brew install git

Output:

==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions and functions have been installed to:
  /usr/local/share/zsh/site-functions

Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/git

Bash

Install:

brew install bash

Update the default shell:

sudo vi /etc/shells

Add the path to the shell you want to use if not already present, then set it:

chsh -s /usr/local/bin/bash

Bash completion

Install:

brew install bash-completion

Output:

==> Caveats
Add the following line to your ~/.bash_profile:
  [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

wget

Handy to have in general (especially if you're copy/paste-ing someone else's commands...like below in this very document):

brew install wget

rsync

Install the latest version instead of using the older macOS supplied version:

brew install rsync

Programming Languages & Web Frameworks

Python

Homebrew installs pip and distribute by default when installing Python:

Install pyenv:

brew install pyenv
pyenv init

# Load pyenv automatically by appending
# the following to ~/.bash_profile:

eval "$(pyenv init -)"

Install pyenv-virtualenv:

brew install pyenv-virtualenv

# Load pyenv-virtualenv automatically by adding
# the following to ~/.bash_profile:

eval "$(pyenv virtualenv-init -)"

Python 3:

pyenv install 3.6.1

If you need Python 2:

pyenv install 2.7.13

To create a virtualenv (replace the Python version number as necessary):

pyenv virtualenv 3.6.1 myenv

To activate the virtualenv and check for updates to the default software:

pyenv activate myenv
pip install -U pip setuptools

If you want the virtualenv to be activated each time you cd into the project directory:

touch ~/Projects/myproject/.python-version
vi ~/Projects/myproject/.python-version

The contents should just be the name of the virtualenv you want to use for the project e.g. 'myenv'.

Django bash completion:

mkdir ~/.django
wget https://raw.githubusercontent.com/django/django/master/extras/django_bash_completion -O ~/.django/django_bash_completion

Add to ~/.bash_profile:

. ~/.django/django_bash_completion

Image processing utils

Install these so Pillow, et al work out of the box:

brew install optipng jpegoptim pngcrush ImageMagick

Ruby

Install:

brew install rbenv

rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:

eval "$(rbenv init -)"

Pick a version:

rbenv install 2.4.1
rbenv global 2.4.1

Data Stores

PostgreSQL

Install:

brew install postgres

Output:

==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/legacy-homebrew/issues/2510

To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see:
  https://www.postgresql.org/docs/9.6/static/upgrading.html

To migrate existing data from a previous minor version (9.0-9.5) of PostgreSQL, see:
  https://www.postgresql.org/docs/9.6/static/pgupgrade.html

  You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`.
  Do not run `brew cleanup postgresql` until you have performed the migration.

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start

Per the instructions, start up PostgreSQL and test that you can connect:

pg_ctl -D /usr/local/var/postgres start
psql postgres

Create a user (the -s means this will be a superuser):

createuser -s web

PostGIS:

brew install libgeoip
brew install postgis

Output:

==> Caveats
To create a spatially-enabled database, see the documentation:
  https://postgis.net/docs/manual-2.2/postgis_installation.html#create_new_db_extensions
If you are currently using PostGIS 2.0+, you can go the soft upgrade path:
  ALTER EXTENSION postgis UPDATE TO "2.3.2";
Users of 1.5 and below will need to go the hard-upgrade path, see here:
  https://postgis.net/docs/manual-2.2/postgis_installation.html#upgrading

PostGIS SQL scripts installed to:
  /usr/local/opt/postgis/share/postgis
PostGIS plugin libraries installed to:
  /usr/local/lib
PostGIS extension modules installed to:
  /usr/local/share/postgresql/extension

Create a spatially enabled database template:

createdb template_postgis
psql -f /usr/local/share/postgis/postgis.sql template_postgis
psql -f /usr/local/share/postgis/spatial_ref_sys.sql template_postgis

To create a spatially enabled database:

createdb -T template_postgis mydbname

MySQL

PostgreSQL is always preferred but sometimes you don't have a choice:

brew install mysql

Output:

==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

Create a database and set permissions for development:

mysql -uroot

CREATE DATABASE project CHARACTER SET UTF8;
GRANT ALL PRIVILEGES ON project.* TO 'web'@'localhost' WITH GRANT OPTION;

MariaDB

This is a drop-in replacement for MySQL by the original authors (forked after Oracle bought Sun):

brew install mariadb

Output:

==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

MySQL is configured to only allow connections from localhost by default

To connect:
    mysql -uroot

To have launchd start mariadb now and restart at login:
  brew services start mariadb
Or, if you don't want/need a background service you can just run:
  mysql.server start

Elasticsearch

This requires java:

brew cask install java
Install the latest using homebrew::
brew install elasticsearch

Output:

==> Caveats
Data:    /usr/local/var/elasticsearch/elasticsearch_testytest/
Logs:    /usr/local/var/log/elasticsearch/elasticsearch_testytest.log
Plugins: /usr/local/opt/elasticsearch/libexec/plugins/
Config:  /usr/local/etc/elasticsearch/
plugin script: /usr/local/opt/elasticsearch/libexec/bin/elasticsearch-plugin

To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch

If you need to control the version of elasticsearch used on a per project basis, download the version you need directly from Elastic.co. From the downloaded and uncompressed elastic-X.Y.Z folder:

bin/elasticsearch

Redis

Install:

brew install redis

Output:

==> Caveats
To have launchd start redis now and restart at login:
  brew services start redis
Or, if you don't want/need a background service you can just run:
  redis-server /usr/local/etc/redis.conf

memcached

Install:

brew install memcached

Output:

==> Caveats
To have launchd start memcached now and restart at login:
  brew services start memcached
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/memcached/bin/memcached

Recommended Tools

The following development tools are not required but strongly recommended.

PyCharm (Professional edition) PyCharm is the preferred IDE for Python/Django development.

iTerm2

SourceTree

Sublime Text Sublime is a great general purpose editing tool. Especially handy if you need to remove formatting from text to get plain text, just copy from Word or the web and paste into Sublime.

Homebrew maintenance

To update your installed brews:

brew update
brew outdated
brew upgrade

Get a check-up from the doctor and follow the doctor's instructions:

brew doctor