Set up macOS for development

A month ago, I switched to macOS from Windows because of its terrible development experience (at least for me). It took me several days to set up macOS, but I’m very happy with the result. In this blog, I want to share my setup.

I assume you are new to macOS. If you’re not, you may still find this blog useful if you are reinstalling your system.

The steps below are tested on macOS Catalina 10.15.4. Feel free to skip any sections you don’t need.

System Updates

First thing you need to do is to make sure your system is up to date. Open System Preferences, go to Software Updates and make sure you don’t have any new software updates.

System Preferences

Here are my personal preferences. Feel free to follow these or ignore them.

  • Trackpad > Tap to click
  • Keyboard > Key Repeat > Fast
  • Keyboard > Delay Until Repeat > Short
  • Keyboard > Text > Disable “Correct spelling automatically”
  • Dock > Automatically hide and show the Dock

You may also want to disable the popup showing accented characters when holding down a key. To do that, open Terminal and run:

defaults write -g ApplePressAndHoldEnabled -bool false

You’ll need to log-out and log back in again for the setting to take effect.

Homebrew

The missing package manager for macOS. But before we install Homebrew, we need to install Command Line Developer Tools for Xcode:

xcode-select --install

Now install Homebrew using the command from Homebrew homepage:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Usage

Install a package (or what Homebrew call a Formula):

brew install <formula>

See if any of your packages need to be updated:

brew outdated

Update a package:

brew upgrade <formula>

Visual Studio Code

Editor is no doubt the most important tool for a developer. If you’re new to programming and need something that just works, I highly suggest Visual Studio Code. It’s getting better and better every day thanks to the awesome team from Microsoft.

Grab it from homepage. You should already know how to install an application inside a .dmg file. If not, open the .dmg file and drag-and-drop Visual Studio Code into Applications folder.

Now let’s configure our editor. Go to Code > Preferences > Settings. In the top-right part, click the button that shows “Open Settings (JSON)” on hover. Paste the following:

{
  "editor.tabSize": 2,
  "editor.rulers": [80, 100, 120],
  "editor.wordWrapColumn": 120,
  "editor.wordWrap": "wordWrapColumn",
  "files.insertFinalNewline": true,
  "files.trimTrailingWhitespace": true
}

Feel free to change these settings to match your preferences. When done, save and close.

To master Visual Studio Code, you should know Command Palette. You can do pretty anything with it. Press Cmd + Shift + P to open it.

Inside Command Palette, search for Shell Command: Install ‘code’ command in PATH. Hit enter when it shows up.

This enables you to run code <filename> in Hyper to quickly open a file in VS Code. You can also open a folder in VS Code. The most common command is code ., which open the current directory.

What makes VS Code great is its ability to customize through the use of extensions.

Oh My Zsh

Oh My Zsh is an open-source driven framework for your zsh config. It comes with a bunch of different plugins, themes, and helpers to make your terminal look awesome inside.

Install it:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Please read Using Oh My Zsh before proceeding. For theme, I use Powerlevel10k. I leave everything else as default.

I also use aliases to save time.

alias brewup="brew update; brew upgrade; brew cleanup; brew doctor"
alias zshconfig="code ~/.zshrc"
alias cppcompile='c++ -std=c++17 -stdlib=libc++'
alias remove_ds="find . -name '.DS_Store' -type f -delete"
alias pip_upgrade="pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U"

Git

Let’s configure Git.

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

I also use aliases for Git. Edit git config file to add your aliases.

code ~/.gitconfig

Mine looks like this:

[user]
	name = Le Bao Hiep
	email = baohiep2013@gmail.com
[alias]
	a = add
	ca = commit -a
	cam = commit -am
	s = status
	pom = push origin master
	pog = push origin gh-pages
	pus = push --set-upstream
	puom = pull origin master
	puog = pull origin gh-pages
	cob = checkout -b
[color]
	ui = auto

This allows me to just type git cam instead of git commit -am.

Python

pyenv

Python is installed by default on macOS, but we don’t want to mess with the system Python at all, so we’ll use pyenv instead. This allows us to have multiple versions of Python.

Install pyenv with Homebrew:

brew install pyenv

When finished, you should see some instruction to add something to your terminal profile. This allows pyenv to automatically load (more details later). Open ~/.zshrc (or run zshconfig) and add this line:

if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)"; fi

We also install a few dependencies suggested by pyenv documentation:

brew install openssl readline sqlite3 xz zlib

Usage

List all available Python versions:

pyenv install --list

Install a specific version of Python:

pyenv install <version>

List all versions installed locally:

pyenv versions

The star (*) indicates which version we’re using. For now, it should be system, which is the default.

Switch to another version:

pyenv shell <version>

If you’re working on a project, you can run:

pyenv local <version>

This will save that Python version to .python-version file. Next time you enter a project in a terminal, pyenv will automatically load that version for you.

pip

pip, the package manager for Python, is also installed by pyenv.

Usage

Install a package:

pip install <package>

Upgrade a package:

pip install --upgrade <package>

Remove a package:

pip uninstall <package>

List installed packages:

pip freeze

virtualenv

virtualenv is a tool that creates an isolated Python environment for each of your projects.

For a particular project, instead of installing required packages globally, it is best to install them in an isolated folder, that will be managed by virtualenv. The advantage is that different projects might require different versions of packages, and it would be hard to manage that if you install packages globally.

Instead of installing and using virtualenv directly, we’ll use the dedicated pyenv plugin pyenv-virtualenv which will make things a bit easier for us. Install it via Homebrew:

brew install pyenv-virtualenv

After installation, add the following line to your .zshrc file:

if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi

Now, let’s say you have a project called myproject. You can set up a virtualenv for that project and the Python version it uses (replace 3.x.x with the version you want):

pyenv virtualenv 3.x.x myproject

See the list of virtualenvs you created with:

pyenv virtualenvs

To use your project’s virtualenv, you need to activate it first (in every terminal where you are working on your project):

pyenv activate myproject

If you run pyenv virtualenvs again, you should see a star (*) next to the active virtualenv.

You can also set your project’s .python-version to point to a virtualenv you created:

pyenv local myproject

Next time you enter that project’s directory, pyenv will automatically load the virtualenv for you.

Node.JS

The recommended way to install Node.js is to use nvm (Node Version Manager) which allows you to manage multiple versions of Node.js on the same machine.

Install it:

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

Final Thoughts

These are most of the tools I’m using for development. I hope you find this blog valuable.

If you found any errors or mistakes, or have some tools that you believe it deserves to be included, please let me know!

4.5 4 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x