Setup for macOS
  • 21 May 2024
  • 2 Minutes to read
  • Dark
    Light
  • PDF

Setup for macOS

  • Dark
    Light
  • PDF

Article summary

Git setup

Depending on the operating system, Git may already be installed.

To determine if it is installed, run: git --version

  • If the response is a git version, then it is already installed.

  • If it is not installed, follow the steps below to install it.

If git is not installed, macOS should prompt you to install it when the version command was unsuccessful.

Python and Node

This setup also helps you achieve deterministic builds and an overall more consistent work environment. You won’t have to manually manage the Python virtualenv locations and names anymore. For Node, global packages are installed based on the version.

The setup makes use of pyenv and nvm, which are version managers for Python and Node respectively. You can think of these tools as scripts that dynamically modify your path environment variable as you switch versions, ensuring that version locations and directories are cleanly separated and that the right version is called when you run python or node in a given directory.

Note: This process refers to python and python3. Before attempting these steps, determine which of these your environment uses and then follow the corresponding instructions.

Python

Complete the following steps to set up your environment for Python.

  1. Install pyenv.

    1. Install Homebrew

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

    2. Install pyenv using Homebrew.
      brew update
      brew install pyenv

  2. Add pyenv to your PATH.

    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc 
    echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc 
    echo 'eval "$(pyenv init -)"' >> ~/.zshrc
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc 
    echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc 
    echo 'eval "$(pyenv init -)"' >> ~/.bashrc
  3. Restart your shell for changes to take effect.
    exec "$SHELL"

  4. Set up your build environment for Python.

    1. If you haven't installed the XCode CLI yet, install it now.
      xcode-select --install

    2. Install the Python build dependencies using Homebrew.
      brew install openssl readline sqlite3 xz zlib tcl-tk

  5. Install a python version and set it as the global default:

    pyenv install <version>
    pyenv rehash
    pyenv global <version>

    replacing <version> with the latest version.

  6. Install Python tools.

    1. Upgrade your pip version: pip install --upgrade pip

    2. Install pipenv: pip install --user pipenv

Node

Complete the following steps to set up your environment for Node and nvm.

  1. Install nvm:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
    wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
  2. Restart your shell for changes to take effect.
    exec "$SHELL"

  3. Install a node version and set it as the global default.
    nvm install 18.16.0
    nvm alias default 18.16.0

  4. Add deeper shell integration using the instructions in GitHub's nvm Deeper Shell Integration documentation. With this functionality, when you change directories the node version switches automatically to match the new directory.

  5. Enable Node Corepack so you can use the latest version of Yarn.
    corepack enable

PostgreSQL for macOS

Add ~/.local/bin and the PostgreSQL bin directory to your PATH variable in the ~/.zshrc file:

export PATH=$HOME/.local/bin:$PATH
export PATH=/library/postgresql/15/bin:$PATH

Yarn setup

Depending on the operating system, Yarn may already be installed.

To determine if it is installed, run: yarn --version

  • If the response is a version, then it is already installed.

  • If it is missing, ensure you have installed Node.

    • If Node is installed, and Yarn is not, install it by running: npm install --global yarn

For more detailed instructions on installing Yarn, refer to the Yarn documentation.


Was this article helpful?