Setup New Mac Mini M1
— macmini — 11 min read
Recently, I just brought a new Mac Mini with the M1 chip. Thought it would be nice to make a post about how I set up my development machine from the ground up.
For the software compatibility, you can use this website to check.
Install Homebrew
The first software to install for me always is Homebrew
.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install git & vim & openjdk
brew install gitbrew install vimbrew install openjdk
Setup Git config
git config --global user.name "Lee Xiang Wei"git config --global user.email "xwlee2009@gmail.com"# Aliasesgit config --global alias.co checkoutgit config --global alias.br branchgit config --global alias.ci commitgit config --global alias.st statusgit config --global alias.unstage 'reset HEAD --'
Install Node.js via nvm
brew install nvm# You should create NVM's working directory if it doesn't exist:mkdir ~/.nvm
Add the following to ~/.zshrc
or your desired shell configuration file:
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
Install LTS version node.
nvm install --LTS
Install yarn.
brew install yarn
Install Docker Desktop for Apple silicon
Download from https://docs.docker.com/docker-for-mac/apple-m1/
Install other software
brew install --cask google-chromebrew install --cask brave-browserbrew install --cask firefoxbrew install --cask iterm2brew install --cask alfredbrew install --cask keka # File archiverbrew install --cask vlc # Video playerbrew install --cask thunder # Downloaderbrew install --cask visual-studio-codebrew install --cask adobe-acrobat-readerbrew install --cask sequel-probrew install --cask postmanbrew install --cask spotifybrew install --cask appcleanerbrew install --cask numi # Calculatorbrew install --cask notionbrew install --cask mark-text # Markdown editorbrew install --cask fliqlo # Screensaversbrew install --cask keepingyouawake # Utility the prevent Mac from entering sleep modebrew tap homebrew/cask-fontsbrew install --cask font-jetbrains-mono # The programming font I use
Install prezto
prezto is the configuration framework for Zsh shell.
It comes with modules and themes that allow you to customize your terminal.
To install prezto, run
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
Copy the configuration files
setopt EXTENDED_GLOBfor rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"done
Append this to your .zprofile
to make sure brew binary can be called when open new terminal.
eval $(/opt/homebrew/bin/brew shellenv)
Update .zprofile
and change below section to vim
...export EDITOR='vim'export VISUAL='vim'...
Select a theme for your terminal
To list all the available themes
prompt -l
To preview a theme
prompt -p <theme>
To set a theme
prompt -s <theme>
Example themes
Install a module for your terminal
You can browse here for the available modules
To add a new module, open ~/.zpreztorc
and add the module to the following section
...zstyle ':prezto:load' pmodule \ 'environment' \ 'terminal' \ 'editor' \ 'history' \ 'directory' \ 'spectrum' \ 'utility' \ 'completion' \ 'prompt' \ # Add new module here...
Then you need to reload ~/.zpreztorc
source ~/.zpreztorc
Install vundle, the plugin manager for vim
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
Add below code to the top of your .vimrc
, these are the plugins I used. Feel free to change the plugin.
" Make Vim more usefulset nocompatiblefiletype off
" Set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()" Alternatively, pass a path where Vundle should install plugins"call vundle#begin('~/some/path/here')
" Let Vundle manage Vundle, requiredPlugin 'gmarik/Vundle.vim'
Plugin 'altercation/Vim-colors-solarized'Plugin 'ervandew/supertab'Plugin 'kien/ctrlp.vim'Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}Plugin 'Raimondi/delimitMate'Plugin 'scrooloose/nerdtree'Plugin 'scrooloose/nerdcommenter'Plugin 'tpope/vim-surround'
" All of your Plugins must be added before the following linecall vundle#end()filetype plugin indent on
" Use the Solarized Dark themeset background=darkcolorscheme solarizedlet g:solarized_termtrans=1let g:solarized_visibility="high"let g:solarized_contrast="high""let g:solarized_termcolors=256
" Use the OS clipboard by default (on versions compiled with `+clipboard`)set clipboard=unnamed" Enchance command-line completionset wildmenu" Allow cursor keys in insert modeset esckeys" Allow backspace in insert modeset backspace=indent,eol,start" Optimize for fast terminal connectionsset ttyfast" Add the g flag to search/replace by defaultset gdefault" Use UTF-8 without BOMset encoding=utf-8 nobomb" Change mapleaderlet mapleader=","let g:mapleader=","" Don't add empty newlines at the end of linesset binaryset noeol" Centralize backups, swapfiles and undo historyset backupdir=~/.vim/backupsset directory=~/.vim/swapsif exists("&undodir") set undodir=~/.vim/undoendif
" Don’t create backups when editing files in certain directoriesset backupskip=/tmp/*,/private/tmp/*
" Respect modeline in filesset modelineset modelines=4" Enable per-directory .vimrc files and disable unsafe commands in themset exrcset secure" Enable line numbersset number" Enable syntax highlightingsyntax on" Highlight current lineset cursorline" Show invisible charactersset listset listchars=tab:▸\ ,eol:¬,nbsp:⋅,trail:•" Highlight searchesset hlsearch" Ignore case of searchesset ignorecase" Highlight dynamically as pattern is typedset incsearch" Always show status lineset laststatus=2" Enable mouse in all modesset mouse=a" Disable error bellsset noerrorbells" Don't reset cursor to start of line when moving around.set nostartofline" Show the cursor positionset ruler" Don't show the intro message when starting Vimset shortmess=atI" Show the current modeset showmode" Show the filename in the window titlebarset title" Show the (partial) command as it's being typedset showcmd" Starting scrolling eight lines before the horizontal window borderset scrolloff=8
" Indentationset tabstop=4set expandtab " Tab in insert mode will produce the appropriate number of spacesset softtabstop=4 " Controls how many spaces will be used with expandtabset shiftwidth=4 " Controls how many columns text is indented with the reindent operation (<< and >>)set autoindent " Copies the indentation level from the previous lineset smartindent " Do smart autoindenting when starting a new line, e.g. after `{` and before `}`set pastetoggle=<F5>
" Strip trailing whitespace (,ss)function! StripWhitespace() let save_cursor = getpos(".") let old_query = getreg('/') :%s/\s\+$//e call setpos('.', save_cursor) call setreg('/', old_query)endfunctionnoremap <leader>ss :call StripWhitespace()<CR>
" Save a file as root (,W)noremap <leader>W :w !sudo tee % > /dev/null<CR>
if has("autocmd") " Treat .json files as .js autocmd BufNewFile,BufRead *.json setfiletype json syntax=javascript " Treat .md files as Markdown autocmd BufNewFile,BufRead *.md setlocal filetype=markdown " Add spell checking and automatic wrapping at the recommended 72 columns autocmd Filetype gitcommit setlocal spell textwidth=72 " 2-space for YAML autocmd Filetype yaml setlocal ts=2 sts=2 sw=2 expandtab " 2-space for JavaScript autocmd Filetype javascript setlocal ts=2 sts=2 sw=2 expandtabendif
" Remove search resultscommand! H let @/=""
" Fast savesnmap <leader>w :w!<CR>
" Change directory to the file being editednmap <leader>cd :cd %:p:h<CR>:pwd<CR>
" Down is really the next linennoremap j gjnnoremap k gk
" Easy escaping to normal modeimap jj <ESC>
" Auto change directory to match current file ,cdnnoremap ,cd :cd %:p:h<CR>:pwd<CR>
" Easier window navigationnmap <C-h> <C-w>hnmap <C-j> <C-w>jnmap <C-k> <C-w>knmap <C-l> <C-w>l
" Resize vsplitnmap <C-v> :vertical resize +5<CR>
nmap <C-b> :NERDTreeToggle<CR>let NERDTreeShowHidden=1
let g:ctrlp_show_hidden = 1
" Create split belownnoremap :sp :rightbelow sp<CR>
" Open splitsnmap vs :vsplit<CR>nmap sp :split<CR>
" Create/edit file in the current directorynmap :ed :edit %:p:h/
" Moving selectionxmap <C-k> :mo'<-- <CR> gvxmap <C-j> :mo'>+ <CR> gv
" Easy access to the vimrcnnoremap <leader>ev :vsplit $MYVIMRC<cr>" Reload vimrcnnoremap <leader>rv :source $MYVIMRC<cr>
To install from command line, run:
vim +PluginInstall +qall
Setup Solarized theme in iTerm2
Save the theme to your machine, then import then into the color preset.
Setup Mac OS
################################################################################ General UI/UX ################################################################################
# Expand save panel by defaultdefaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool truedefaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Expand print panel by defaultdefaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool truedefaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
# Save to disk (not to iCloud) by defaultdefaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
# Disable automatic capitalization as it’s annoying when typing codedefaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false
# Disable smart dashes as they’re annoying when typing codedefaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# Disable automatic period substitution as it’s annoying when typing codedefaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false
# Disable smart quotes as they’re annoying when typing codedefaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
# Disable auto-correctdefaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
################################################################################ Trackpad, mouse, keyboard, Bluetooth accessories, and input ################################################################################
# Increase sound quality for Bluetooth headphones/headsetsdefaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40
# Disable press-and-hold for keys in favor of key repeatdefaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
# Set a blazingly fast keyboard repeat ratedefaults write NSGlobalDomain KeyRepeat -int 1defaults write NSGlobalDomain InitialKeyRepeat -int 10
# Show language menu in the top right corner of the boot screensudo defaults write /Library/Preferences/com.apple.loginwindow showInputMenu -bool true
################################################################################ Screen ################################################################################
# Save screenshots in PNG format (other options: BMP, GIF, JPG, PDF, TIFF)defaults write com.apple.screencapture type -string "png"
# Disable shadow in screenshotsdefaults write com.apple.screencapture disable-shadow -bool true
# Enable subpixel font rendering on non-Apple LCDs# Reference: https://github.com/kevinSuttle/macOS-Defaults/issues/17#issuecomment-266633501defaults write NSGlobalDomain AppleFontSmoothing -int 1
# Enable HiDPI display modes (requires restart)sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
################################################################################ Finder ################################################################################
# Finder: allow quitting via ⌘ + Q; doing so will also hide desktop iconsdefaults write com.apple.finder QuitMenuItem -bool true
# Finder: disable window animations and Get Info animationsdefaults write com.apple.finder DisableAllAnimations -bool true
# Set Desktop as the default location for new Finder windows# For other paths, use `PfLo` and `file:///full/path/here/`defaults write com.apple.finder NewWindowTarget -string "PfDe"defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/Desktop/"
# Finder: show all filename extensionsdefaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Finder: show status bardefaults write com.apple.finder ShowStatusBar -bool true
# Finder: show path bardefaults write com.apple.finder ShowPathbar -bool true
# Keep folders on top when sorting by namedefaults write com.apple.finder \_FXSortFoldersFirst -bool true
# When performing a search, search the current folder by defaultdefaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
# Disable the warning when changing a file extensiondefaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Avoid creating .DS_Store files on network or USB volumesdefaults write com.apple.desktopservices DSDontWriteNetworkStores -bool truedefaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Automatically open a new Finder window when a volume is mounteddefaults write com.apple.frameworks.diskimages auto-open-ro-root -bool truedefaults write com.apple.frameworks.diskimages auto-open-rw-root -bool truedefaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true
# Show item info near icons on the desktop and in other icon views/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist
# Show item info to the right of the icons on the desktop/usr/libexec/PlistBuddy -c "Set DesktopViewSettings:IconViewSettings:labelOnBottom false" ~/Library/Preferences/com.apple.finder.plist
# Enable snap-to-grid for icons on the desktop and in other icon views/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
# Increase grid spacing for icons on the desktop and in other icon views/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist
# Increase the size of icons on the desktop and in other icon views/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:iconSize 80" ~/Library/Preferences/com.apple.finder.plist/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:iconSize 80" ~/Library/Preferences/com.apple.finder.plist/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:iconSize 80" ~/Library/Preferences/com.apple.finder.plist
# Use list view in all Finder windows by default# Four-letter codes for the other view modes: `icnv`, `clmv`, `glyv`defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
# Expand the following File Info panes:# “General”, “Open with”, and “Sharing & Permissions”defaults write com.apple.finder FXInfoPanesExpanded -dict \ General -bool true \ OpenWith -bool true \ Privileges -bool true
################################################################################ Dock, Dashboard, and hot corners ################################################################################
# Change minimize/maximize window effectdefaults write com.apple.dock mineffect -string "scale"
# Minimize windows into their application’s icondefaults write com.apple.dock minimize-to-application -bool true
# Don’t animate opening applications from the Dockdefaults write com.apple.dock launchanim -bool false
# Speed up Mission Control animationsdefaults write com.apple.dock expose-animation-duration -float 0.1
# Remove the auto-hiding Dock delaydefaults write com.apple.dock autohide-delay -float 0
# Remove the animation when hiding/showing the Dockdefaults write com.apple.dock autohide-time-modifier -float 0
# Automatically hide and show the Dockdefaults write com.apple.dock autohide -bool true
# Don’t show recent applications in Dockdefaults write com.apple.dock show-recents -bool false
################################################################################ Activity Monitor ################################################################################
# Show the main window when launching Activity Monitordefaults write com.apple.ActivityMonitor OpenMainWindow -bool true
# Visualize CPU usage in the Activity Monitor Dock icondefaults write com.apple.ActivityMonitor IconType -int 5
# Sort Activity Monitor results by CPU usagedefaults write com.apple.ActivityMonitor SortColumn -string "CPUUsage"defaults write com.apple.ActivityMonitor SortDirection -int 0