跳转至

MacOS Guide Chapter 1

Reference

This guide covers the basics of setting up a development environment on a new Mac. Whether you are an experienced programmer or not, this guide is intended for everyone to use as a reference for setting up your environment.

XCode and Homebrew

Xcode

Xcode is an integrated development environment for macOS containing a suite of software development tools developed by Apple for developing software for macOS, iOS, watchOS and tvOS.

Download and install it from the App Store or from Apple's website.

For installing Xcode command line tools run:

Text Only
1
xcode-select --install

It'll prompt you to install the command line tools. Follow the instructions and you'll have Xcode and Xcode command line tools both installed.

XQuartz

XQuartz is Apple Inc.'s version of the X server, a component of the X Window System for macOS. It might be useful if you are developing software for macOS, it's available for download here.

Homebrew

Homebrew calls itself The missing package manager for macOS and is an essential tool for any developer.

Installation

Before you can run Homebrew you need to have the Command Line Tools for Xcode installed. It include compilers and other tools that will allow you to build things from source, and if you are missing this it's available through the App Store > Updates. You can also install it from the terminal by running the following:

Text Only
1
sudo xcode-select --install

To install Homebrew run the following in a terminal:

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

hit Enter, and follow the steps on the screen.

Setting up your PATH

To make the Homebrew-installed programs available in your shell, you need to add your Homebrew installation location to your $PATH. This is done for you already on macOS 10.14 Mojave and newer. For older versions of macOS, do the following:

You change your path by adding /usr/local/bin to your PATH environment variable. This can be done on a per-user basis by adjusting PATH in your ~/.bash_profile. To do this, run:

Text Only
1
echo 'PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

(If you're using zsh, you should do this for ~/.zshrc in addition to ~/.bash_profile.)

Alternatively, you can also insert /usr/local/bin before the first line of /etc/paths to change the global default paths order, for all users and all major shells. An admin password will be required if you modify the file.

Then, to be able to use brew you need to start a new terminal session. After that you should make sure everything is working by running:

Text Only
1
brew doctor

If everything is good, you should see no warnings, and a message that you are "ready to brew!".

Using Homebrew

To install a package (or Formula in Homebrew vocabulary) simply type:

Text Only
1
brew install <formula>

To update Homebrew's directory of formulae, run:

Text Only
1
brew update

Note: If that command fails you can manually download the directory of formulas like this:

Text Only
1
2
3
cd /usr/local/Homebrew/
git fetch origin
git reset --hard origin/master

To see if any of your formulas need to be updated:

Text Only
1
brew outdated

To update a formula:

Text Only
1
brew upgrade <formula>

Homebrew keeps older versions of formulas installed on your system, in case you want to roll back to an older version. That is rarely necessary, so you can do some cleanup to get rid of those old versions:

Text Only
1
brew cleanup

If you want to see what formulae Homebrew would delete without actually deleting them, you can run:

Text Only
1
brew cleanup --dry-run

To see what you have installed (with their version numbers):

Text Only
1
brew list --versions

To search for formulas you run:

Text Only
1
brew search <formula>

To get more information about a formula you run:

Text Only
1
brew info <formula>

To uninstall a formula you can run:

Text Only
1
brew uninstall <formula>

Homebrew-Cask

Homebrew-Cask extends Homebrew and allows you to install large binary files via a command-line tool. You can for example install applications like Google Chrome, Dropbox, VLC and Spectacle. No more downloading .dmg files and dragging them to your Applications folder!

To see if an app is available on Cask you can search on the official Cask website. You can also search in your terminal:

Text Only
1
brew search <package>

Example Applications

Quick Look plugins

These plugins add support for the corresponding file type to Mac Quick Look (In Finder, mark a file and press Space to start Quick Look). The plugins includes features like syntax highlighting, Markdown rendering, preview of JSON, patch files, CSV, ZIP files and more.

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
brew install --cask \
    qlcolorcode \
    qlstephen \
    qlmarkdown \
    quicklook-json \
    qlprettypatch \
    quicklook-csv \
    betterzip \
    webpquicklook \
    suspicious-package
App Suggestions

Here are some useful apps that are available on Cask.

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
brew install --cask \
    alfred \
    android-file-transfer \
    appcleaner \
    caffeine \
    cheatsheet \
    colloquy \
    docker \
    doubletwist \
    dropbox \
    google-chrome \
    google-hangouts \
    flux \
    1password \
    rectangle \
    sublime-text \
    superduper \
    transmission \
    valentina-studio \
    vlc