Programmer's Guide to Setting Up a Mac OS X Machine

I created this todo list for my own use if I ever need to reset any of my computers or set up on a new computer. While I was making the list, I realized it would make for a good blog post too. The post assumes that you are a vim user, or at least are willing to give vim a shot, which I personally highly recommend you do. It is also primarily written with Python and LaTeX coding in mind, so I make no claim that what follows provides a system ready for any other type of coding. However, if the programming language of your choice is supported by command line and vim then what follows should be useful regardless.

The rest assumes you have a fresh install of Mac OS X Mountain Lion, though some if not all should apply to some older versions and to non-fresh copies too.

1) Security

First things first, do the following to make sure access to your system is secure:

  • Ensure all Admin users have a strong password set-up. (System Preferences\Users & Groups)
  • Disable the Guest user. (System Preferences\Users & Groups)
  • Enable File Vault. (System Preferences\Security & Privacy)

2) Chrome and Its Extentions

Chrome is my browser of choice, so the second on the list is installing Chrome. Also install the following extensions:

  • AdBlock Plus
  • DoNotTrackMe
  • Facebook Disconnect
  • KB SSL Enforcer
  • iReader
  • Vimium (if you would like vim-like mouse-less navigation in Chrome)

3) XCode and Its Command Line Tools

Next, install XCode using the App Store. It is free, at least as of the time of the writing of this article. Once it is done, run XCode, go to XCode\Preferencess... and then the Downloads tab and download and install Command Line Tools which are necessary for compiling C and C++ code from the command line using gcc.

4) MacPorts

Getting a package manager is going to make your life as a programmer much easier. There are two well-known package managers for Mac OS X: Homebrew and MacPorts. I personally use MacPorts, though admittedly I have never tried Homebrew. Many programmers seem to prefer Homebrew, so if you have not tried either, you might want to try both and pick the one you prefer. The rest of this article has MacPorts commands but the Homebrew equivalents should be relatively easy to figure out.

Install MacPorts by downloading the required package from https://www.macports.org/.

After MacPorts is installed run the following:

  • Install bash and bash-completion:
    • sudo port install bash bash-completion
  • To make sure all the rest of the ports are installed with bash completion support, edit /opt/local/etc/macports/variants.conf and add a single line containing:
    • +bash_completion
  • Install the following ports to get MacVim, Mercurial, and Git:
    • sudo port install macvim git-core mercurial
  • For Python, install the following:
    • sudo port install python27 python31 py27-pip py31-pip py27-ipython py31-ipython
  • Select MacPorts' Python as the default:
    • sudo port select --set python python27 (or python31 if you prefer Python 3.1.)
  • Optionally, install the following useful ports:
    • sudo port install wget nmap watch pwgen wireshark sudo grep man googlecl coreutils

5) Customizing bash

Mac OS X Mountain Lion ships with bash version 3.2. We want to use the latest version installed by MacPorts (as of the time of writing, 4.2.) So open up Terminal and go to menu item Terminal\Preferences... and change Shells open with: to /opt/local/bin/bash -l. This will make Terminal use the latest bash provided by MacPorts.

Next, edit ~/.bash_profile and add the following, if they are not already there:

# Use vim anytime an editor is needed by bash
export EDITOR="mvim -v"

# Use vi keyboard shortcuts in bash
# (for example, Escape then j will move the cursor one left in Terminal)
set -o vi

# Enable colors
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

# Installing MacPorts should automatically add something similar to the following
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

# bash-completion - enables smart bash completion
if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then
    . /opt/local/etc/profile.d/bash_completion.sh
fi


# Set the prompt. Personalize this line to modify how the bash prompt looks like.
PS1="\\A \\w $ "

Finally, create ~/.inputrc and add the following line to it:

set editing-mode vi

This enables vi mode in readline enabled programs, most importantly the interactive Python shell and iPython.

6) MacVim Plugins

Next is to personalize MacVim to make it look and feel like it is yours. First, install pathogen at https://github.com/tpope/vim-pathogen. Next, install some colorschemes. I personally like to use the Github repository maintained by flazz for this. Follow their installation guide which uses pathogen. That being said, I also really like the "distinguished" colorscheme. You can download it here.

Finally, some of the plugins that I have learned to like a lot are:

  • jedi-vim is a must-have for Python coding.
  • EasyMotion for easy navigation in a file.
  • tcomment for commenting and uncommenting code in all sorts of files.
  • surround.vim for surrounding blocks of code in various surroundings.

7) LaTeX

For LaTeX, I also use MacPorts. Simply run the following, or a smaller subset of the following if you do not need everything here.

sudo port install texlive \
texlive-basic \
texlive-bibtex-extra \
texlive-bin \
texlive-bin \
texlive-bin-extra \
texlive-common \
texlive-context \
texlive-fonts-recommended \
texlive-fontutils \
texlive-generic-recommended \
texlive-lang-english \
texlive-latex \
texlive-latex-extra \
texlive-latex-recommended \
texlive-luatex \
texlive-math-extra \
texlive-metapost \
texlive-pictures \
texlive-plain-extra \
texlive-pstricks \
texlive-science \
texlive-xetex

8) Alfred 2

This one is useful for everyone, not just coders and mathematicians. Alfred 2 is great productivity tool for Mac OS X that is quite similar to the Spotlight Search feature but much more powerful. Get it at https://www.alfredapp.com/.

9) TotalTerminal & iTerm 2

TotalTerminal allows quick access to a Terminal window by simply pressing Ctrl + ~, similar to most FPS games. Get it at https://totalterminal.binaryage.com/.

iTerm 2 is a replacement for the built-in Terminal app. Get it at https://www.iterm2.com/. (Thanks to reddit user thoomfish for mentioning this.)

10) Terminal Commands

This one is not really a set-up step as much as it is a reminder of some very useful Terminal commands that are Mac OS X specific (as far as I know):

  • Using the clipboard: pbcopy copies what is given to it by stdin into the clipboard. pbpaste pastes what is in the clipboard to stdout.
  • You can open the curent directory in Finder by typing open .. In fact, you can open a file the same way opening it in finder would work by typing open <filename>.
  • Use opensnoop to see which files are being modified live. You can narrow it down to a process or a particular file, by using the -p or -f arguments, respectively.
  • Make the computer speak (literally) by typing say <sentence>. This comes in handy for keeping track of what your shell script is doing while you are away from the computer.
  • Assuming you have set vi mode for bash, hit Escape+v to edit the current command line you are writing in vim. Very useful if you are working on a long command.
  • You might also want to consider installing and using zsh since it has some very nice features (e.g. zmv). (Thanks to reddit user TigerWolf for the suggestion.)

11) Fonts

Finally, I like to install a nice monospace font for programming purposes. My personal pick as of lately has been "Droid Sans Mono" which you can download from here. You then need to add this line to your .vimrc file for it to use this font:

set guifont=Droid\ Sans\ Mono:h12

This is the font used by default on this website for all code-snippets.

Comments