Skip to content

Instantly share code, notes, and snippets.

@GLMeece
Last active November 11, 2024 03:15
Show Gist options
  • Save GLMeece/fff65c2fbca5b80f87b7c3f3aa8c135d to your computer and use it in GitHub Desktop.
Save GLMeece/fff65c2fbca5b80f87b7c3f3aa8c135d to your computer and use it in GitHub Desktop.
New macOS Machine Setup

New macOS Machine Setup

This guide is based on my own experience, but also draws on other guides. It is primarily oriented towards those doing code-related stuff (e.g., I'm mostly an SDET, but is also applicable to those doing either Python or Web-based development).

A couple of other examples:

Most of the setup will use the terminal. For more details on how to setup an awesome terminal experience on the Mac, see my guide Steps to Terminal Enlightenment on a Mac (tweaking your terminal for fun and profit), which in fact includes some of these steps (you're welcome!).

Verify or Install Apple's Command-line Tools

First, make sure that you have Apple's command-line tools installed by executing:

xcode-select -p

If you get a path back (like /Applications/Xcode.app/Contents/Developer) then you're good to go. Otherwise:

xcode-select --install

In the dialog that pops up, click Install and click Agree for the license agreement.

Note: If you get a message that says "Can't install the software because it is not currently available from the Software Update server." then you will need to download it from here (look for Command Line Tools...).

Install 🍺 Homebrew

This is the first thing I normally do. As I've said before, haters gonna hate, but this is the quickest, easiest way to get a commonly-referenced package manager on the Mac.

To install Homebrew, run this command:

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

To make sure it's all working correctly, execute:

brew doctor

Finally, just to make sure everything's up-to-date:

brew update

Terminal Elightenment

As mentioned above, you may want to follow my Gist on Steps to Terminal Enlightenment on a Mac.

NodeJS Installation

This section assumes you're going to do at least some JavaScript development. Unless you're a white-knuckled "Vanilla JS only, baby!" kind of developer, you know you're going to install NodeJS and NPM.

You can install NodeJS via Homebrew, but...let's not. Why? Because, as useful as it is for many installation tasks, it also updates installs willy-nilly, as the needs of other packages dictate. If you're going to do web development that relies on the Node ecosystem, you should manage it and its installations yourself.

Having said that, let's consider how we want to install NodeJS along with the Node Package Manager (NPM). The most commonly-recommended way to manage your Node versions is with Node Version Manager (NVM).

NVM Install

  1. First, make sure there isn't already a version of Node installed - this will mess things up once we attempt to use NVM.
brew uninstall --ignore-dependencies node 
brew uninstall --force node 
  1. Install NVM with Homebrew and create a directory in your home directory:
brew update 
brew install nvm
mkdir ~/.nvm
  1. Update your ZSH (Z-shell) resource:
nano .zshrc

# Add the following line towards the end of your ZSH resource file, where you're doing your `export` stanzas:

# Node Version Manager
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

# control-o to save; control-x to exit
  1. Now, let's pick the version of NodeJS you want to install (pick the latest, or choose whatever your team is currently working with). Note that those links are just for reference as we're going to let NVM do the actual installation. If you want NVM to show you what versions are available to install, execute: nvm ls-remote. In this example, I'm going to install Node 18.12.1:
nvm install 18.12.1

This install will "pick" this version of Node/NPM as your default, but you can choose the version you want by executing nvm use VERSION_YOU_WANT_TO_USE. Learn more about using it and installing other versions by reading the article Managing Node versions or Installing Multiple Versions of Node.js Using nvm.

Git, Make, PyEnv, and Nano

You can install/update all of these by hand, but...why? macOS already has both make and nano installed (as well as Python, but let's not even go there), but those are older versions and we want newer and more capable installs. We'll use Homebrew:

brew install git make pyenv nano

Git Minimal Setup

You'll probably want to do more later, but at least do this:

# Create & Edit the .gitconfig file:
nano .gitconfig

# Add your user info stanza
[user]
 email = [email protected]
 name = Your Name

# control-o to save; control-x to exit

PyEnv - install Python

We're going to use this Homebrew install of PyEnv to manage our Python version, for much the same reason we're using NVM to manage our NodeJS/NPM versions. In this example, I'm installing Python 3.10.8:

pyenv install 3.10.8
# Let's set the above as our 'default' Python version:
pyenv global 3.10.8
# Let's verify that this is so:
pyenv version
# Should return something like: 3.10.8 (set by /Users/YOURUSERNAME/.pyenv/version)

# Now, add the following to the end of your .zshrc using nano or whatever:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
pyenv global 3.10.8
alias pip=$PYENV_ROOT/shims/pip

Note on Virtual Environments: I've found that PyEnv and some Language Servers (such as the Robocorp Robot Framework LSP) don't get along with the standard virtualenv. However, PipEnv seems to work well. I'll perhaps create separate install instructions for PipEnv and virtual environments.

Additional Notes on Python

Here are some more guides about using Python on macOS:

Nano - Now with Syntax Coloring!

Let's give nano some flair (15 pieces is the minimum!):

# Let's just brute-force creating the .nanorc and include all syntax highlighters:
echo include "/usr/local/share/nano/*.nanorc" >> ~/.nanorc

Apps

VS Code sync: https://code.visualstudio.com/docs/editor/settings-sync

# I'll put stuff here later - I promise!

Other Tweaks and Tools

Use MacBook Fingerprint Reader for sudo

This is a cool trick I learned and I really like it. Read my gist on HOWTO Leverage the Fingerprint Reader on a MacBook to Validate SUDO.

Hardening your Mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment