Skip to content

ampersand-five/mac-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mac Setup

What I use to setup a Mac

Table of Contents

Install

Check installations to see if they have different Intel and Apple packages.

Xcode

  • Has code that it installs system wide that many things will need to use on a Mac
  • From Apple Mac App Store
  • Let fully install, might take several hours
  • Open once and accept terms and conditions
  • Open Preferences/Settings and go to the 'Locations' tab, then on that page for the 'Command Line Tools' option, pick a Xcode
  • On Apple silicon, Mx chip, after opening Xcode, it should prompt to install Rosetta

iTerm 2

  • Better CLI
    • Some features: Split panes, global search, copy/paste, configurability, 24 bit and 256 color mode, more
  • Download: https://iterm2.com/
  • After installation, in settings, set to have infinite scrollback
  • Find a color theme if you'd like: iTerm2 themes
  • Silence the 'Last Login' line when opening the terminal by adding a file to home directory: touch ~/.hushlogin

Mac: See Hidden Files

  • $ defaults write com.apple.finder AppleShowAllFiles -bool TRUE;killall Finder

VS Code

  • IDE
  • Download https://code.visualstudio.com/
  • Configuration:
    • Set terminal.integrated.scrollback, terminal.integrated.persistentSessionScrollback, and terminal.integrated.shellIntegration.history values to 9999999999999 to have basically unlimited history

Github Desktop

Docker Desktop

Homebrew

  • Package Manager
  • Install instructions
    • In July 2022, installation was: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • From the installation page, it says:
    This script installs Homebrew to its preferred prefix
    - /usr/local for macOS Intel
    - /opt/homebrew for Apple silicon
    - /home/linuxbrew/.linuxbrew for Linux
    
  • 🍎 Apple silicon:
    • Follow install instructions
    • TL;DR: they want this to be put in the .zshrc file:
    export HOMEBREW_PREFIX="/opt/homebrew";
    export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
    export HOMEBREW_REPOSITORY="/opt/homebrew";
    export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}";
    export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
    export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";
    
    • If a ~/.zshrc file does not exist yet, create one and put the above in it

Install Bash with Homebrew

  • See this article: Upgrading Bash on macOS
  • TL;DR of article:
    • Mac has an old version of bash installed from 2007 (As of Aug. 2021)
    • You want to:
      1. Install the latest version of Bash
      2. “Whitelist” new Bash as a login shell
      3. Set new Bash as the default shell
    $ brew install bash
    $ sudo vim /etc/shells
    
    # Add to bottom of file:
    
    # Intel Mac
    /usr/local/bin/bash
    
    # Apple silicon Mac
    /opt/homebrew/bin/bash
    
    # The above will whitelist the Bash installed by Homebrew
    
    # Now set the Homebrew Bash as the default:
    
    # Intel Mac
    $ chsh -s /usr/local/bin/bash
    
    # Apple silicon Mac
    $ chsh -s /opt/homebrew/bin/bash
    
    # Change bash for root user
    
    # Intel Mac
    $ sudo chsh -s /usr/local/bin/bash
    
    # Apple silicon Mac
    $ sudo chsh -s /opt/homebrew/bin/bash
  • Tell scripts to use whatever version of Bash they see first on the PATH. You can do this by putting this line at the top of scripts. This tells it to inspect the PATH on the local machine and use whatever Bash it finds first:
    #!/usr/bin/env bash
    echo $BASH_VERSION
  • Both System and User Bash will exist in tandem
    • System default Bash: /bin/bash
    • User installed Bash, using the above method:
      • /usr/local/bin/bash # Intel Mac
      • /opt/homebrew/bin/bash # Apple silicon Mac

ZSH with Brew

  • Install Zsh with Homebrew
  • Check system is pointing to Brew installation of ZSH
    • Intel
      • This is going to be like the bash installation, in that, by using brew, it will install zsh in /usr/local/bin/zsh and the system version will be in /bin/zsh. If you echo PATH, the default path has /usr/local/bin listed before /bin and the system will run the first one it finds when searching locations listed in the PATH, so it will run the brew one first. All this meaning, your system should be automatically pointing to the brew version. You can double check though, if you want, by checking with which -a zsh and it should show two versions, then check the PATH and see which is listed fist on the path.
    • 🍎 Apple silicon
      • Same as above but /opt/homebrew is not on the default PATH. However, above when we installed Homebrew, this was taken care of when we created a ~/.zshrc file and put a line that added /opt/homebrew to the PATH
    • System ZSH: /bin/zsh
    • User installed ZSH using this method: /usr/local/bin/zsh or /opt/homebrew/bin/zsh
  • Do the same thing we did above, for bash, now for Zsh:
    $ brew install zsh
    $ sudo vim /etc/shells
    
    # Add to bottom of file:
    
    # Intel Mac
    /usr/local/bin/zsh
    
    # Apple silicon Mac
    /opt/homebrew/bin/zsh
    
    # The above will whitelist the Zsh installed by Homebrew
    
    # Now set the Homebrew Zsh as the default:
    
    # Intel Mac
    $ chsh -s /usr/local/bin/zsh
    
    # Apple silicon Mac
    $ chsh -s /opt/homebrew/bin/zsh
    
    # Change bash for root user
    
    # Intel Mac
    $ sudo chsh -s /usr/local/bin/zsh
    
    # Apple silicon Mac
    $ sudo chsh -s /opt/homebrew/bin/zsh
  • Set IDE to use the Homebrew ZSH for its integrated terminal, if it has one
    • VS Code: Code -> Preferences -> Settings, open settings, search for terminal.integrated.defaultProfile, set the value to be the Homebrew ZSH for your operating system

Font

  1. Find a preferred font
  2. With the preferred font, we can patch it to add programmer glyphs using Nerd Fonts
    • Nerd Fonts has a script that can patch fonts to add the Nerd Fonts glyphs to a font
    • Many fonts are already patched ready for download, like Fira Code pathed with Nerd Font
  3. Check README on current installation instructions, but read the bottom of it
    • Make sure to install the patched fonts. In the example FiraCode, the readme is copied from FiraCode, verbatim, and then, has new instructions at the bottom added to it that are specific to patched Nerd Fonts. This is a link to the FiraCode section to read and follow.
    • TL;DR: For FiraCode, don't click the download link in the README, that's the direct link to FiraCode original (not patched with Nerd Fonts). You need to go into each of the folders at the top and download a font from there. Quick link example
  4. Configure apps to use font (instructions below for Macs):
    • iTerm2: iTerm2 -> Preferences -> Profiles -> Text, set Font to the font and tick the checkbox for 'Use ligatures'
    • VS Code: Code -> Preferences -> Settings, open settings
      • Search editor.fontLigatures, set true
      • Change the base font for VS Code with editor.fontFamily which also applies to the integrated terminal, or just change the font family for the integrated terminal with terminal.integrated.fontFamily
        • The value for the default font says something like Menlo, Monaco, 'Courier New', monospace. Add the font to the front of that list, example: 'FiraCode Nerd Font', Menlo, Monaco, 'Courier New', monospace
        • Evaluates fonts in order and applies the first one it finds installed
  • Zsh plugin manager, loads fast
    • Allows installation of Oh My Zsh and Prezto plugins
    • zshrc file referenced in next steps has some things in it that use zinit
  • Install with Homebrew (preferred) or from Github
    • Homebrew preferred because it's easy to update with Homebrew
      • Make a .zshrc file at ~/.zshrc if one doesn't exist yet

      • As of July 2022, the Homebrew installation of Zinit requires this to be added to a .zshrc file:

        source $(brew --prefix)/opt/zinit/zinit.zsh

        • This file sets up command completion for Zinit
  • Every once in a while update Zinit and it's plugins
    • brew update zinit or zinit self-update
    • zinit update for all plugins
    • zinit update <plugin> for a specific plugin

~/.vimrc File

~/.p10k.zsh File

  • Personal preference, if you have a .p10k.zsh file, put it in your home folder now before we do the .zshrc file in the next step as it will install and use p10k and try to configure it, or use the one you have if it is put in the home directory now.

~/.zshrc File

  • On Mac, zsh will load the /etc/zshrc file first and then the ~/.zshrc file. Anything in the ~/.zshrc file overrides the /etc/zshrc file.
  • See the zshrc file in this repo

Github CLI

  • brew install gh
  • gh auth login
  • Copilot:
    • gh extension install github/gh-copilot
    • gh copilot config - Set usage analytics to no.

LSD

Fun

DevUtils

HTTPie

  • Nicer curl for API's and URL's
  • Website
  • Homebrew, have a Desktop UI incoming, but not available as of mid 2022

Beekeeper Studio

pyenv

  • Python version management
  • Github
  • Homebrew
  • Add to .zshrc:
    # pyenv
    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="/Users/demon_slayer/.pyenv/shims:${PATH}"
  • After installing, check that you have the recommended build environment
    • 🍎 Apple silicon, as of Sept. 2022, xz was not installed, had to brew install xz to get it. All the other ones were pre-installed (zlib, readline, tcl-tk, etc.)
  • Install some python versions and set one globally
    • $ pyenv install -l
    • $ pyenv install 3.x.x
    • $ pyenv global 3.x.x

Poetry

  • Python package, dependency, environment management
  • Website
  • Installation
    • Add Poetry install location to your PATH in .zshrc file:
      • export PATH="$HOME/.local/bin:${PATH}"
  • Poetry defaults to create virtual environments in a central location, to create inside the project in a .venv folder, set poetry config virtualenvs.in-project true

Commands

  • Clear python pycache: $ find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf

Data Science Additionals

Package Manager

Micromamba

  • Conda, from Anaconda, is a package installer. Poetry is another package installer, but Poetry is only Python. Conda can do python and non-python packages which is what data science needs because there are some packages that are not python that are used in data science. Mamba is a replacement for Conda as it is faster.
  • Install Micromamba, which a small self-contained mamba without conda bloat.
  • Create a ~/.mambarc file to use conda-forge instead of defaults for licensing reasons (this can also go in an environment file in a repo):
channels:
    - conda-forge

Poetry

  • Another option is to use Poetry.
  • When using Poetry with Data Science libraries, some libraries or functions, like ARIMA, will rely on XGBoost. XGBoost relies on OpenMP for parallel processing. On macOS, the OpenMP runtime library (libomp.dylib) isn't installed by default. Install it with: brew install libomp

Jupyter

Use Jupyter in VS Code.

Other, Not Organized

Change Apple Emoji for JoyPixels

Packages for Python Projects:

black, isort, pytest, pytest-cov, pre-commit

  • Black is an active linter, flake8 is a passive one

About

Setup a Mac for Coding - Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages