Setting up a Brand New Mac for Development

Setting up a Brand New Mac for Development

A walkthrough of techniques and sensible defaults for an Apple development environment.

I just got a new MacBook Pro, and I decided to research the fastest, most efficient method to set up a clean, organized, and up-to-date development environment for my new computer. I wrote about some of these steps in my front end web development setup post, and now I’m going to go into more detail.

I documented everything I did after taking the Mac out of the box. This post will be useful to anyone setting up a new Mac, whatever your preferred apps and settings are. Simply change variables as necessary.

Goals

I’m a front end web developer, and most of the software I install will pertain to that. I still have much to learn, but this process will setup my Mac to run Git, Jekyll, Gulp, Sass, an Apache server, and more.

View on GitHub

I’ve included all the commands from this article without any of the explanation on a GitHub readme. Feel free to fork, modify, and keep for your own future records.

macOS Sierra v. 10.12 Setup

The Setup Assistant will launch once you turn the computer on. Here you’ll enter your language, time zone, Apple ID, and so on. I choose not to use “Migration Assistant”, and set up my computer from scratch. The first thing you should do is update macOS to get the latest security updates and patches.

If you’re setting up for the first time, you’ll have to install App Store software through the App Store itself, but if you’ve installed them before, you’ll be able to use Homebrew, Cask, and Mas to install all your programs from the command line.

Homebrew

Install the Homebrew package manager. This will allow you to install almost any app from the command line. In previous versions, you’d have to install XCode or Command Line Tools before using this, but that step is no longer necessary.

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

Mac App Store

The Mac App Store command line interface, or mas-cli, will allow you to install from the App Store.

brew install mas
Sign in

If you haven’t already logged into the App Store, you can do so now.

mas signin [email protected]

Brewfile

Now I’ll create a file called Brewfile in my main directory, which will list all the programs I want on the computer, and install them in a bundle.

Open Terminal, which will be in your home folder by default (/Users/you). Create the file.

touch Brewfile

You can edit the file with TextEdit, or by typing nano Brewfile. If you choose to edit with nano, you can save the file by typing Control + O to save, and Control + X to exit the file.

List of Programs

Here are all the programs I intend to install with a brief description. You can choose to add or subtract any programs you’d like. They’re all free.

  • Cask – an extension to Homebrew that will allow you to install almost any program that exists for a Mac
  • Git – for version control
  • npm – Node Package Manager (yes, we’re installing package managers with package managers. Welcome to current year!
  • Brackets – my current text editor of choice. Feel free to install Atom, VSC, or alternative instead or in addition to Brackets
  • f.lux – Night Shift for your Mac. Save your eyes!
  • Firefox – a front end dev should have all the major browsers installed
  • Gimp – a free Photoshop alternative
  • Google Chrome – web browser
  • MAMP – simplify and sandbox your development environment, if you choose
  • Opera – web browser
  • Spectacle – excellent free app for resizing your windows
  • Sequel Pro – excellent free GUI for MySQL databases
  • VLC Media Player – it plays everything!
  • Slack – the communication app
  • Sip – indispensable free app to gather the color/HEX code of any pixel on your screen
  • Simplenote – my note-taking app of choice
  • Todoist – my to-do app of choice
  • Numbers – the Apple equivalent of Excel – should come preinstalled
  • Pages – the Apple equivalent of Word

Below are the entire contents of my Brewfile, which will install all the above programs with a single command.

tap 'caskroom/cask'

brew 'git'
brew 'npm'

cask 'brackets'
cask 'flux'
cask 'firefox'
cask 'gimp'
cask 'google-chrome'
cask 'mamp'
cask 'opera'
cask 'spectacle'
cask 'sequel-pro'
cask 'vlc'

mas 'Numbers', id: 409203825
mas 'Pages', id: 409201541
mas 'Slack', id: 803453959
mas 'Sip', id: 507257563 
mas 'Simplenote', id: 692867256 
mas 'Todoist', id: 585829637

Now simply run this command to install the bundle.

brew bundle install

Bash

Config – ~/.bash_profile

Now that we have all our programs installed and Homebrew all nice and new, we should create a simple script to keep Homebrew up to date. I found this handy command on this Best of Homebrew gist.

First, create a .bash_profile dotfile in your home folder.

touch .bash_profile

We’ll create a bash alias to combine all the commands to keep Homebrew clean and up to date.

alias brewup='brew update; brew upgrade; brew prune; brew cleanup; brew doctor'

Run the following command.

source ~/.bash_profile

Now you can run brewup to update, upgrade, prune, cleanup, and doctor Homebrew. It’s a good idea to do this often, even daily.

brewup

GitHub

Config – ~/.gitconfig

The first thing you should do with Git is set your global configuration. We can do this by running a lot of small commands which will update the Git configuration file.

git config --global user.name "First Last"

Or we can just create the Git configuration file and input it all ourselves.

touch .gitconfig

Here I’ll input my name, email, GitHub username, some aliases to be able to type less and do more, and connect Git to the OS X Keychain so I don’t have to type my username and password every time I want to push to GitHub.

[user]
    name = First Last
    email = [email protected]
[github]
    user = username
[alias]
    a = add
    ca = commit -a
    cam = commit -am
    s = status
    pom = push origin master
    pog = push origin gh-pages
    puom = pull origin master
    puog = pull origin gh-pages
    cob = checkout -b
[credential]
    helper = osxkeychain

With the above aliases, I can run git s instead of git status, for example. The less I have to type repeatedly, the happier I am.

SSH

If you use SSH (Secure Shell) to connect to any remote hosts via the command line, you can simplify the process.

Config – ~/.ssh/config

Create an SSH config file.

touch .ssh/config

Add the following contents, changing the variables for any hosts that you connect to. Using the below will connect to -i key.pem [email protected]. You can remove the IdentityFile if you don’t connect with a pem key. The output will then simply be [email protected] and you’ll be prompted for password authentication.

Host example
    HostName example.com
    User example-user
    IdentityFile key.pem

Now just run the alias to connect.

ssh example

Generate SSH key

You can generate an SSH key to distribute.

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Node.js

We’re going to use Node Version Manager (nvm) to install Node.js.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash

Install the latest version.

nvm install node

Restart terminal and run the final command.

nvm use node

Confirm that you are using the latest version.

node -v

You can also test with which node, which will output your Node path and version number.

/Users/yourusername/.nvm/versions/node/v7.8.0/bin/node

Node Package Manager

I have npm installed, and npm is mostly used locally for projects. The only thing I use globally at the moment is Gulp.

Gulp

Install Gulp globally.

npm install --global gulp-cli

Ruby

Ruby is required to run Jekyll, a popular static site generator. I’m going to download Ruby Version Manager (rvm) to make sure I have the updated version of Ruby without messing with the built-in system Ruby.

Download rvm

\curl -sSL https://get.rvm.io | bash -s stable

Install Ruby version

You can look for and install the latest version by number, or by running the below command.

rvm install ruby-head

You can run rvm list to see the full list of versions available. To use the latest version, find the number and run this command.

rvm --default use 2.4.0

Confirm that you are using the latest version.

rvm -v

You can also test with which ruby, which will output your Ruby path and version number.

/Users/yourusername/.rvm/rubies/ruby-2.4.0/bin/ruby

Install bundler

Gem is the Ruby package manager that we’re going to use to install bundler…a package manager. This is necessary to use Jekyll and useful for any other Ruby project.

gem install bundler

Virtual Hosts

If you’re using MAMP like I am to set up an Apache/MySQL/PHP/Python/Ruby environment, here is a mini-tutorial on setting up virtual hosts.

Terminal Colors

I like to set a color scheme for my terminal. You can do this from Preferences, or by finding one online and opening the .terminal file, which will open a terminal with the new preferences. You can then save it as default. Add this to your bash_profile to enable colors in Terminal.

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad

Preferences

I have a few preferences I like to set.

  • Keyboard > Text > Disable “Correct spelling automatically”
  • Security and Privacy > FileVault > On (makes sure SSD is securely encrypted)
  • Security and Privacy > Firewall > On (extra security measure)
  • Security and Privacy > General > App Store and identified developers
  • File Sharing > Off
  • Users & Groups > Login Items > Spectacle, Flux (I like these to open on startup)

A few more commands to change some defaults.

Show Library folder

chflags nohidden ~/Library

Show hidden files

defaults write com.apple.finder AppleShowAllFiles YES

Show path bar

defaults write com.apple.finder ShowPathbar -bool true

Show status bar

defaults write com.apple.finder ShowStatusBar -bool true

Conclusion

That sums it up for my current preferences on setting up a 2015 era MacBook Pro running macOS Sierra. I hope it helped speed up your process, or gave you ideas for the next time you’re setting up a new computer. This should set the groundwork for adding new software and processes in the future.

I know there is a lot I’m still missing. Some of my goals for 2017 involve setup with popular software like Vagrant, VirtualBox, Docker, and Ansible. If there’s anything you do differently, please feel free to let me know!

I also recently acquired an actual PC running Windows, so I can probably do some of my articles in a Windows environment upon request.

Share to Twitter

Write a response

Your email address will not be published.

13 responses

  • Oscar says:

    Thanks for sharing this setup. I actually cloned your repo and tweaked it to include docker and docker-machine, plus VirtualBox. You can take a look at https://github.com/SharePointOscar/mac

    Thanks again, this makes life easier especially since I just setup the new MacBook Pro with this script!

    Cheers,
    Oscar

  • Anton says:

    Hi Tania,
    Talking about popular virtualization tools you mentioned (Docker, Vagrant, VB etc) I’d suggest Docker to learn deeper, because nowadays it is widely used in production and test environments as the main DevOps tool. I used all of them and stuck in Docker because of its huge images warehouse on DockerHub, simplicity of packaging and deploying, system resources isolation, low memory consumption and so on. In other words you pack and deliver on server only your app and environment and nothing more. Vagrant and VirtualBox are usually used as just virtual machines with guest OS.
    As for Ansible – I use it as orchestration tool for delivering builds on remote servers via ssh and it is very handful due to its, so to speak, agentless tool. All you need is ssh access and prepared scripts (playbooks).
    So, Docker + Ansible is a comprehensive toolbox, swiss knife, to perform DevOps tasks. Try it and you won’t regret 🙂

  • Pera says:

    I’m also interested in your Windows setup.

    Great work!

  • Sam S says:

    Hi Tania,

    Love your blogpost! I have used Brackets before, but at a certain moment, it kept lagging like hell for reasons. Now I’m using Visual Studio Code, which I’m absolutely loving it so far. It’s also very easy to use with Git in VS Code.

  • Thanks for writing this article. 🙂

  • Paul says:

    Great list!!!, just one thing to point out. I think you might have a typo in “touch .bash_proflile”

  • Douglas says:

    Thanks! Your work is noticed, put to use, and appreciated greatly by a random fellow macbook user.

    I have an older machine that I’ve tweaked so many times and everything works but couldn’t tell you half of what I’ve done to it over the past 5 years. So this guide was exactly what I was looking for. Thanks again 🙂

  • Ted Martin says:

    If you don’t mind telling, what Mac did you get? Even though they’ve received a lot of poor coverage, I’m a big fan of the 2016 MacBooks. Another great article!

    • Tania says:

      Actually, I got the previous model MacBook Pro, which was Early 2015. It was the lower tier one, at 13″, but it was a few hundred dollars cheaper than the new one with almost the same specs, and I like the old keyboard more.

  • Rocker irwin says:

    To me it is a bad idea to buy a Mac for development. There is nothing special about a Mac and yet costs much much more than the PC version with same specs if not better. If you are concerned about windows, there are hundreds of other Linux distributions. I seriously don’t get it. Can you tell me why you bought a Mac ?

    • Tania says:

      It doesn’t matter what you use: Mac or Windows. Vim or Emacs. Tabs or spaces. PHP or Python. If all the options didn’t have merit, there wouldn’t be an argument. This list is not meant to be an endorsement for or against anything, just one person’s web development workflow. Learn. Be open minded. Try new things. Research. Discover what works best for you. – Me

  • A.Prather says:

    Thank you for sharing… If its not too much to ask. Upon request, please share what you’ve done or would do on Windows, the same way you did with Mac.

Write a response