Blog   About  Archives

Setting up a new Mac

In this post, I’d like to quickly cover going through the process of setting up a new machine to tinker around a bit in my spare time.

Some background:

I finally retired my 2009 MacBook Pro (I know, rather late). But this gave me a great opportunity to go through setting up my machine with all that I needed off the bat. This obviously wouldn’t have been possible without some other awesome users who had published a lot of useful guidance for me to follow. I tweaked some small things here and there to find my best fit.

Assumptions:

Getting Started:

I always begin by enabling the tap to click which I’m not sure why Apple doesn’t ship out by default.

I then proceeded to change my localhostname and computername to change from the generic one generated by default. Once the names are set, we’ll flush the DNS cache.

$ sudo scutil --set LocalHostName <new host name> 
$ sudo scutil --set ComputerName <new host name>
$ dscacheutil -flushcache

A quick restart and voila, dunebuggy was alive and well!! Before we get into the other configuration areas, let’s make sure we have the XCode Command Line Tools installed. You can simply do that by-

$ xcode-select --install

Homebrew

There are a few options available for Package Managers when it comes to Mac, but the most popular and my absolute favorite is Homebrew. Let’s get that installed on your mac by entering this command in the terminal

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

You can restart your terminal and type brew doctor to check the status. Also, we’ll need to ensure that our system picks the libraries installed by Homebrew at /usr/local/bin v/s the default OSX libraries that come pre-built. So, you’ll need to modify your PATH variable in your ~/.bash_profile file. We can hold on that for now as we’ll set up Z Shell (zsh) and you can configure your ~/.zshrc at a later point (I promise, not too late).

Homebrew-Cask

Cask extends the functionality of Homebrew and allows you to install large binary files via command line. Goodbye .dmg files !! We can enable that by

brew tap caskroom/cask

You can find more details about Cask here.

I went ahead and installed a few items that will supercharge QuickLook for me by extending the previews that I can see by highlighting and hiting ‘Space Bar’.

brew cask install \
    qlcolorcode \
    qlstephen \
    qlmarkdown \
    quicklook-json \
    qlprettypatch \
    quicklook-csv \
    betterzip \
    webpquicklook \
    suspicious-package

Furthermore, I installed my text-editor of choice, web browser and media player by

brew cask install \
    visual-studio-code \
    vlc \
    google-chrome \
    postman

For any other application you are trying to look for, just do brew search <keyword>, for example: brew search

iTerm2

iTerm is a great alternative to Apple’s default terminal and offers tonnes of customizability. Highly recommended. We can get iTerm by a simple brew formula as evidenced earlier-

brew cask install iTerm2

Some customizations I’ve made:

Once you have iTerm ready, we’ll install Z-Shell (zsh) and Oh My ZSH. I’ve already talked about zsh earlier, and what Oh my ZSH allows you to do is to manage your zsh configuration and improve your overall terminal experience.

Once again, we use homebrew

brew install zsh

Install Oh my ZSH

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

This command will change your default shell from bash to zsh.

Making changes to ~/.zshrc

With all the packages we’ve installed via Homebrew, we want to make sure our mac uses them instead of the OSX defaults. I’m including a snippet from my ~/.zshrc file. Feel free to customize and modify as you deem fit. This is akin to modyfing your ~/.bash_profile, only this is for your Z Shell.

# Setting PATH
export PATH=/usr/local/bin:/usr/local/share/python:$HOME/bin:$PATH 

# Setting ZSH Theme.
ZSH_THEME="pygmalion"

# Enabling which plugins I want to use with zsh
plugins=(git colored-man colorize pip python brew osx zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh

# Setting aliases
alias zshconfig="code ~/.zshrc"
alias ohmyzsh="code ~/.oh-my-zsh"

#Setting Visual Studio Code as default Text Editor
export EDIOTR=code

We’ll add a few more nice additions to zsh. Starting with Tree,

brew install tree

You can find the man pages for Tree here. For instance, try running tree -L 2 in your terminal and then change to tree -L 1. Very useful way of highlighting your directory structure.

We will also install ack

brew install ack

This is like supercharing your grep needs. You can even modify the ~/.ackrc file to change how ack is configured. Man pages link here.

Once you’ve made the modifications to your shell and your shell config profile, reload zsh by

source ~/.zshrc

You’ll do this basically anytime you make any changes to your ~/.zshrc file.

Git Setup

At this point, we’re ready to setup git on our machine, but first we need to install it

brew install git

Once git is installed, you can quickly verify the status of the install by git install check If the which git command doesn’t return /usr/local/bin/git, check your PATH in the ~/.zshrc and make sure the it’s ordered correctly.

We’ll then proceed to enter our Git user details

git config --global user.name "John Doe"
git config --global user.email "john.doe@abc.xyz"

We’ll also cache our credentials so that git doesn’t ask us for our credentials every single time we try to commit. We can do this by

git config --global credential.helper osxkeychain

SSH Key Generation

Let’s first check if you already have a SSH key, by typing ls -al ~/.ssh. If there is no output in terminal, then you can proceed to create a new key. Github documentation on the subject.

We’ll create a new Elliptic Key using the ssh-keygen function.

ssh-keygen -t ed25519 -C "your_email@example.com"

You can read more about ED25519 here. We’ll add the SSH Key to the SSH agent by

eval "$(ssh-agent -s)"

Once that is done, we’ll open our ~/.ssh/config file in and make minor modifications to automatically load the keys into the SSH agent and store passphrases in your OSX keychain. (Applicable for OSX 10.12 or later)

Host *
 AddKeysToAgent yes
 UseKeychain yes
 IdentityFile ~/.ssh/id_ed25519

We’ll finally complete the process by running,

ssh-add -K ~/.ssh/id_ed25519

Run pbcopy < ~/.ssh/id_ed25519.pub and paste the results in your GitLab account settings. Similar options are available within Github and Bitbucket as well.

Setting up your ~/.gitignore file

This is how I’ve setup my ~/.gitignore file.

# Folder view configuration files
.DS_Store
Desktop.ini
.AppleDouble
.LSOverride

# Thumbnail cache files
._*
Thumbs.db

# Files that might appear on external disks
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Compiled Python files
*.pyc

# Compiled C++ files
*.out

# Application specific files
venv
node_modules
.sass-cache

# Icon must end with two \r
Icon

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

Once you’ve modified the file, run this command to ensure that the config is loaded correctly

git config --global core.excludesFile ~/.gitignore

Python and Java

OSX default ships with Python 2.7. To get Python 3, just run

brew install python

Don’t delete 2.7 as there are some dependent libraries which will probably break. Remember, to start Python 3 in your shell, you’ll execute python3 instead of python. Similar logic applies for pip, so it’ll be pip3 instead. To learn more about how to manage different environments with Python, I suggest looking at pyenv documentation.

Java does not come pre-installed with OSX, so we need to install that on our own. We will not use Oracle JDK as the licensing model has changed. We’ll use OpenJDK instead. Once the tar.gz has been downloaded, we’ll navigate to the directory where the file has been downloaded and run the following command

tar xvf jdk.tar.gz -C ~/

This will ensure that extration takes place in our home directory. We’ll modify ourPATHin ~/.zshrc to include bin and add JAVA_HOME

export PATH=/usr/local/bin:/usr/local/share/python:./jdk/Contents/Home/bin:$HOME/bin:$PATH 
JAVA_HOME=./jdk/Contents/Home/

Final Wrap Up

You can finally do a quick sanity check by using Stronghold. Remember to use pip3

pip3 install stronghold
stronghold

In the end, I set up Google Cloud SDK, Firebase CLI and that was it. I hope this proves useful in your journey of getting your Mac ready.

I got a lot of help from Sourabh Bajaj’s excellent post. There are a lot more goodies on there, so please do check it out.

Written on Feb 18, 2019.