Author: Matthias Cuntz, mc (at) macu (dot) de
Modified: 11.07.2020
Inspired by guides of Dirk Avery, Vinicius De Antoni, Sourabh Bajaj, Nicolas Hery.
This is a reminder for myself how to setup a new Mac or updating the OS, which might be useful for others. The repository includes some of my dot-files as a reference.
From support.apple.com:
- Download a macOS installer such as macOS Catalina from the App Store. When the macOS installer opens, quit it without continuing installation.
- Format a USB flash drive of at least 12 GB storage as Mac OS Extended with name InstallCatalina, for example.
- In Terminal type:
sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/InstallCatalina
Also from support.apple.com:
- Connect USB drive, restart while holding Option (alt) key.
- Select Install macOS.
- Format Volume with APFS in Disk Utility.
- Install macOS.
The steps are intented to be done (roughly) in order.
- Check for system updates
Check for updates of macOS in System Preferences > Software Update.
- Set preferences of macOS and standard apps
Set System Preferences such as:
- Sharing > Computer Name,
- unsetting all tickboxes in Mission Control,
- set Keyboard > Modifier Keys… > Caps Lock Key to No Action
Set preferences in standard macOS apps such as:
- Terminal
- set Shell > When the shell exists: to Close if the shell exited cleanly
- unset tickbox Advanced > Set locale environment variables on startup
- Finder
- set tickbox Advanced > Show all filename extensions
- Set the default shell
Apple is now using zsh as its default shell. If you want to stay with bash, change it in the terminal:
chsh -s /bin/bashTo get rid of the nagging reminder that the default shell is now zsh every time you open a new terminal window, set in your .bash_profile:
export BASH_SILENCE_DEPRECATION_WARNING=1 - Restore backup
Transfer files from you backup media either directly or using a Time Machine backup.
- Xcode
A full Xcode installation is not always needed. Most often, the Xcode Command Line Tools (CLT) are enough, for example for Homebrew. But some development software needs a full Xcode installation such as the FreePGI Fortran Compiler. So one can, for example, install the Xcode CLT only, and install the full Xcode only if another program demands it.
Install the Xcode CLT from the terminal:
xcode-select --installThe full Xcode can be installed from the App Store. You have to open it once and confirm the Usage Agreement in order to use the bundled tools.
- App Store
Check your account in the App Store. There are bundled apps such as Keynote, Numbers, etc., which you should open once to get over the welcome screens and offered tutorials.
It also shows you a list of previously installed apps on other systems. Install what you still want and open it once.
My essential apps from the App Store are:
Keynote/Pages/Numbers, iMovie,\ Engauge Digitizer, The Unarchiver, WordService, HiddenMe. - XQuartz
XQuartz is the X-window system running on macOS, needed for ∗nix GUI programs. Get it from XQuartz.
- Homebrew
Install Homebrew for easy ∗nix package installation.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"- GNU compiler and netCDF software
The gcc suite includes gfortran. Install the netcdf-C version, which comes with ncdump, etc., ncview and nco. One can also install cdo with homebrew. We install cdo by hand later using the install_netcdf script because cdo is quite a bit faster when compiled with the Intel compiler and not with the GNU compiler.
for i in ghostscript gcc netcdf cmake udunits proj jasper gsl ; do \ brew install ${i} ; done brew cask install java for i in antlr@2 geos gdal nco ncview ; do brew install ${i} ; done
- Install more practical software
Some more practical software such as imagemagick for images, ffmpeg for movies, htop for extended top, pandoc to convert between markup languages, fd for a faster find, and ripgrep for grepping across a directory tree; plus some others.
for i in wget imagemagick ffmpeg enscript htop graphviz pkg-config pandoc \ doxygen tree git fd bat ripgrep ; do \ brew install ${i} ; done brew install fzf /usr/local/opt/fzf/install
- GNU compiler and netCDF software
- Set your default shell #2
Apple moved to zsh because of the license change of bash from GPLv2 to GPLv3 with its version 4.0. The current bash shell on macOS is hence 3.2 from 2007. If you want to use the latest version of bash, install it with Homebrew, “whitelist” the new shell as a login shell, and choose it as your default login shell:
brew install bash # add the following line to /etc/shells # /usr/local/bin/bash sudo nano /etc/shells chsh -s /usr/local/bin/bash
Note that your shell scripts will probably still use the Apple default bash shell because they often have the shebang line
#!/bin/bash. The most portable way to write scripts is to use#!/usr/bin/env bashas your shebang. This will take the first bash in your$PATH, which would now be/usr/local/bin/bash.You can now use bash-completion with the new bash shell.
brew install bash-completion@2You then have to put the following lines in your .bash_profile to use bash-completion:
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d" [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && source "/usr/local/etc/profile.d/bash_completion.sh"
You can do the exact same steps for the zsh shell. Apples version is rather new but if you want to have the newest developments, install zsh with homebrew, whitelist it and use it as your default shell. If you use zsh, you might want to check out Oh My ZSH for easy configuration of zsh.
- Emacs
I used to use Aquamacs, but use Spacemacs now. The latter is very fast, but has a steep learning curve. At the moment I am not using the two most praised modes: helm and evil. I also needed quite some configuration in the
dotspacemacs/user-configsection of .spacemacs.To install Spacemacs:
brew tap d12frosted/emacs-plus brew install emacs-plus sudo ln -s /usr/local/opt/emacs-plus@26/Emacs.app /Applications cd ${HOME} if [[ -f .emacs ]] ; then mv .emacs .emacs.bak ; fi if [[ -d .emacs.d ]] ; then mv .emacs.d .emacs.d.bak ; fi git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
I also installed the font Source Code Pro by cloning the repository and dragging the OTF folder into Font Book.
And I immediately install aspell for spell checking within Spacemacs.
brew install aspell - LaTeX
One can download from MacTeX or use a homebrew cask. I have chosen homebrew’s cask this time because I use the BasicTeX installation and I hope that homebrew will handle the update between years, which is always a hassle otherwise. The full MacTex installation including all GUIs and programs is:
brew cask install mactexThe minimal LaTeX installation is:
brew cask install basictexIf you chose BasicTeX, then some common LaTeX packages can be installed with:
sudo tlmgr update --self ; \ for i in wasysym german titlesec wasy elsarticle \ supertabular lineno helvetic textpos multirow subfigure appendix lipsum \ dinbrief a0poster wallpaper collection-fontsrecommended dvipng kastrup \ boondox newtx type1cm ucs dvipng a0poster floatflt enumitem lastpage \ hyphenat footmisc chemfig units ntheorem algorithms cleveref a4wide \ lettrine mdframed needspace preprint xifthen ifmtarg algorithmicx \ changepage sidecap sttools marginnote draftwatermark everypage fontinst \ fltpoint tabfigures mnsymbol mdsymbol collection-fontutils fontaxes was \ pdfcrop latexmk fncychap tabulary varwidth framed capt-of ; do \ sudo tlmgr install ${i} ; done
- Freeware
Some essential Freeware for me:
- AppCleaner, for removing apps and all their traces,
- Adobe Reader, because Preview has problems with some PDFs,
- Firefox Developer Edition, Safari is not always supported. Chrome is probably the most supported browser. I use Opera as my standard browser at the moment,
- LaTeXiT, exporting LaTeX equations as graphics,
- Rectangle, moving windows with keystrokes.
- Skype, video calls,
- SourceTree, git GUI originally for bitbucket but works with other git repositories as well.
- Spotify, streaming music,
- VLC, video player for all formats,
Other less essential Freeware that I use:
- Panoply, which needs Java,
- FreePGI Fortran compiler, which needs a full Xcode installation,
- DeepL, like Google Translate.
- Myriad Pro
I like the Myriad Pro font and AGU journals currently use it. The Myriad Pro font comes with the Adobe Acrobat Reader.
To install for non-LaTeX programs, one can install in Font Book the four otf-files from the directory ‘/Applications/Adobe Acrobat Reader DC.app/Contents/Resources/Resource/Font’.
An extended set of glyphs are given in the zip file ‘MyriadPro.zip’:
unzip MyriadPro.zip and drag the folder with the .otf files into Font Book.To install Myriad Pro for LaTeX, using the Adobe fonts, one can launch the following commands in terminal:
for i in fontinst fltpoint tabfigures mnsymbol mdsymbol collection-fontutils ; do \ sudo tlmgr install ${i} ; done git clone https://github.com/sebschub/FontPro.git cd FontPro mkdir otf FONT=MyriadPro cp "/Applications/Adobe Acrobat Reader DC.app/Contents/Resources/Resource/Font/"${FONT}*.otf otf/ ./scripts/makeall ${FONT} echo y | sudo ./scripts/install sudo updmap-sys --enable Map=${FONT}.map sudo -H mktexlsr kpsewhich ${FONT}.map cd .. \rm -fr FontPro
- Python
macOS Catalina (10.15) still comes with Python version 2.7.16 as its default version. Official support for Python 2 has ended Januar 2020. So you want to install Python 3. Installation of Python versions can be a real mess at times, as noted by XKCD:
So I am using pyenv now, and if I am motivated also pyenv-virtualenvwrapper. See the great article pyenv: Multi-version Python development on Mac by Dirk Avery.
To install pyenv with homebrew:
brew install pyenv brew install openssl readline sqlite3 xz zlibYou have to set the following in your .bash_profile so that the shell always finds the currently chosen Python version as first entry.
export PYENV_ROOT="${HOME}/.pyenv" export PATH=${PYENV_ROOT}/bin:${PATH} if command -v pyenv 1>/dev/null 2>&1 ; then eval "$(pyenv init -)" ; fi
- pyenv 101
After starting a new shell, for example by doing
exec $SHELL, you can start installing and using different Python versions:pyenv install --list pyenv install 3.8.3 pyenv rehash pyenv global 3.8.3Remember that you always have to rehash after you installed a new version.
Note that I install as:
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.8.3because I use wxPython, which needs Python to be framework. See the pyenv wiki.
pyenv provides also anaconda and miniconda, with which you can use conda environments:
pyenv install miniconda3-4.7.12 pyenv rehash pyenv shell miniconda3-4.7.12 conda create --name testproject conda activate testprojectYou can then install (conda and pip) packages in the testproject:
conda install numpy scipy matplotlibTo return to the default Python version:
conda deactivate pyenv shell --unsetIf git tells gettext not found after installing anaconda/miniconda, see Nicolas Hery.
You can also use virtual environments with pyenv:
pyenv-virtualenvwrapperYou have to put the following in your .bash_profile:
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
Virtual environments can then be created as:
pyenv virtualenv 3.8.3 testproject pyenv activate testproject pyenv install ipythonThis virtual environments can then be used as any installed Python version with pyenv.
- Essential Python packages
Anaconda comes with hundreds of packages. I tend to use either an official Python version or miniconda and install my essential packages with pip or conda. These are currently in my main environment:
numpy, scipy, matplotlib, cartopy, basemap, seaborn, ipython, jupyter, pandas, netcdf4, statsmodels, scikit-learn, xlrd, mpi4py, schwimmbad, tqdm, xarray, numexpr, bottleneck, wxpython, sphinx, sphinx_rtd_theme, pytest, pytest-cov, flake8and mostly this subset in the virtual environments:
numpy, scipy, matplotlib, seaborn, ipython, pandas, netcdf4, xlrd, flake8# essential subset for i in numpy scipy matplotlib seaborn ipython pandas netcdf4 xlrd flake8 ; do \ pip install ${i} ; done # other standard packages for i in cartopy jupyter statsmodels scikit-learn schwimmbad tqdm xarray numexpr \ bottleneck wxpython sphinx sphinx_rtd_theme pytest pytest-cov ; do \ pip install ${i} ; done # install basemap directly from github pip install https://github.com/matplotlib/basemap/archive/master.zip # mpi4py will be installed after installing openmpi later
Replace pip with conda if using conda environments. There is also a conda package for basemap.
- pyenv 101
- locate
Create locate database so that you can search files with the locate command:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist - Payware
Install Payware, which is for me:
- Microsoft Office,
- Antidote, spell and grammar checker for English and French,
- Papers, reference manager,
- NAG compiler, very meticulous Fortran compiler,
- Intel compiler, C/C++/Fortran compiler producing very fast code,
- CyberGhost, VPN client,
- IDL, interactive data language.
- Additional software
Install additional software from you institution or similar such as VPN clients, cloud services, etc. For INRAE this is: Symantec Antivirus, GlobalProtect VPN, StorageMadeEasy.
- netcdf4_fortran and openmpi development packages
Use the script install_netcdf to install netcdf4_fortran and openmpi development packages for different Fortran compilers. The script is well documented and we just describe the general steps.
- Look for the latest version numbers of netcdf4_fortran and openmpi (addresses are given in install_netcdf) and set them below donetcdf4_fortran and doopenmpi.
- Set both donetcdf4_fortran and doopenmpi to 1.
- Check that
prefix=/usr/local. - Set Fortran compiler, e.g.
fortran_compilers="gfortran". - For PGI, you also have to set the
pgipath.
After having installed openmpi, one can also install mpi4py in python:
env MPICC=/usr/local/openmpi-4.0.4-gfortran/bin/mpicc pip install mpi4py - cdo
hdf5 from homebrew is not thread-safe so cdo will need the -L flag if piping.
alias cdo="cdo -L"
Also Apple’s clang is not yet OpenMP-enabled so that cdo will not use OpenMP. cdo is running also much faster when compiled with Intel.
ToDo
So I install cdo using the install_netcdf script. One will need to add OpenMP to the CFLAGS:
CFLAGS=-fopenmp(-fopenmp for gfortran and ifort, -openmp for nagfor and pgfortran, -qopenmp for others).