Getting a Mac ready for development

Apple computers are awesome: they are fancy machines which make your daily life easier. But every developer knows that there are a lot of things to install and configure before you can actually start programming. This guide is an overview of how I configure my Mac for development. I’m sure everyone has his own habits regarding tools and configurations, but this guide should get you started!

Note: I wrote this guide while configuring my Mac running El Capitan (OS X 10.11). Things might (and probably will) change for future OS X versions.

Command line tools

Fish shell

Fish is “a smart and user-friendly command line shell for OS X, Linux, and the rest of the family.” It makes your life in the terminal a lot easier: it comes with autosuggestions, man page completion, nice colours, web-based configuration, and a clean and simple scripting language.

Download Fish from their website and run the installer. After the installation you must manually set the shell as your default shell:

$ chsh -s /usr/local/bin/fish

Fish functions

You can easily create your own function with Fish. To do so, you must create a file with the function name in the ~/.config/fish/functions directory.

Fish prompt

The prompt is a Fish function itself, which you can fully customize. Here is the prompt I use for Fish (~/.config/fish/functions/fish_prompt.fish):

function fish_prompt --description 'Write out the prompt'

    set -l last_status $status
    
    if not set -q __fish_prompt_normal
        set -g __fish_prompt_normal (set_color normal)
    end
    
    # PWD
    set_color $fish_color_cwd
    echo -n (prompt_pwd)
    set_color normal
    
    printf '%s ' (__fish_git_prompt)
    
    if not test $last_status -eq 0
        set_color $fish_color_error
    end
    
    echo -n '$ '

end
Opening files with Chocolat editor

I have a Fish function which opens a given folder or file with my favorite editor (Chocolat, see below). Put this function in ~/.config/fish/functions/chocolat.fish:

function chocolat
    if test -z "$argv"
        open . -a Chocolat
    else
        open $argv -a Chocolat
    end 
end
sudo !!

Fish has no sudo !! command. If you really need it, you can create your own (~/.config/fish/functions/sudo.fish):

function sudo
    if test "$argv" = !!
        eval command sudo $history[1]
    else
        command sudo $argv
    end
end

Xcode

First you need to install Xcode from the Mac App Store. Once installed, you also need the Command Line Tools, you can initiate the download process by executing $ xcode-select --install in the Terminal.

Vim

Vim is my favorite editor in the console. No need to install it because it’s part of the command line tools. You can completely customize it: I have the following Vim config in ~/.vimrc:

" Vim config

set number                      "Line numbers are good
set backspace=indent,eol,start  "Allow backspace in insert mode
set showcmd                     "Show incomplete cmds down the bottom
set showmode                    "Show current mode down the bottom
set gcr=a:blinkon0              "Disable cursor blink
set visualbell                  "No sounds

" enable syntax highlighting
syntax on   

" indentation
set autoindent
set smartindent
set smarttab
set shiftwidth=4
set softtabstop=4
set tabstop=4
set expandtab

MacPorts

MacPorts is a package manager for OS X, which is quite similar to FreeBSD Ports. Yeah, I know, some people prefer Homebrew
Download the MacPorts installer from their website (make sure to download it for the correct operating system) and install MacPorts.

If you are using Fish (MacPorts does it automatically if you use Bash, which is the default one on OS X), you must manually set your PATH correctly. Add the following line to ~/.config/fish/config.fish:

$ set -xg PATH /opt/local/bin /opt/local/sbin $PATH

After installing MacPorts it’s good practice to update MacPorts and the ports tree:

$ sudo port selfupdate

Git

Git comes together with the Xcode command line tools.
Make sure to correctly setup your Git config, since your username and email will appear in every commit you author.

$ git config --global user.name "Some username"
$ git config --global user.email some_mail@example.com

Go

Since I’m a Go developer, installing Go is one of the first things I do on a new Mac. Installing Go can be done very easily using MacPorts:

$ sudo port install go

You must also define your Go path. More info about how the $GOPATH should look like can be found here.
Using Fish shell, you must add it to ~/.config/fish/config.fish:

set -xg GOPATH ~/Code/Go/

Using Bash:

$ export GOPATH=~/Code/Go/

To make this permanent (for Bash) you must put the command in your .bash_profile.

Optionally you also add your Go bin folder to your $PATH. For Fish, you must again put it in ~/.config/fish/config.fish:

$ set -xg PATH $GOPATH/bin $PATH

C++

Xcode comes with Clang compiler by default. If you need Gcc, you must install it using MacPorts:

$ sudo port install gcc5

Now you need to enable the MacPorts Gcc version, so you actually use it when executing the gcc command. (Apple linked the Gcc command to Clang…):

$ port select --list gcc
Available versions for gcc:
    mp-gcc5
    none (active)

$ sudo port select --set gcc mp-gcc5

You can verify your installation in the Terminal: $ gcc -v

Python

Python 2.7 comes bundled with the OS X command line tools. If you need a newer version of Python, you can install it using MacPorts:

$ sudo port install python35

You can also install pip, an awesome tool for installing extra Python packages/modules:

$ sudo easy_install pip

MAMP (Mac OS X Apache MariaDB PHP)

Doing web development? Then you probably want to install MAMP. See this blogpost for detailed instructions.

You know Caddy? Probably not, but it’s surely worth checking out! It’s a very easy and simple webserver which works perfectly with PHP-FPM.

Other ports

Install some other useful ports you might need:

$ sudo port install cmake wget pandoc mtr sl boost qt5 nodejs

Composer

Install Composer, the PHP package manager:

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

Sass

Install the Sass tool for preprocessing CSS stylesheets:

$ sudo gem install sass

LaTeX

You can download and install a complete LaTeX bundle called MacTex. It comes with a .pkg installer and doesn’t require any additional configuration.

Software

This is a list of software I use (or just know). The tools listed here are worth checking out and are surely not new for most Mac users.

Editors

There are a lot of good code editors available for Mac. My personal favorite is Chocolat. Here is an overview of some good editors for OS X:

General programming:

Web development:

IDEs:

LaTeX editor: Texpad (paid)

Utilities

Some other useful apps for developers.
FTP:

Although I think you shouldn’t use a visual Git client and stick to the command line, there are some good Git clients for OS X:

Others: