An open API service indexing awesome lists of open source software.

https://github.com/mcuntz/setup_mac

Setting up macOS for scientific computing
https://github.com/mcuntz/setup_mac

macos setup setup-guide setup-macos

Last synced: 2 months ago
JSON representation

Setting up macOS for scientific computing

Awesome Lists containing this project

README

          

# C-c C-e for export within Emacs
# C-c C-l for editing hyperlinks
#+OPTIONS: toc:nil
#+OPTIONS: broken-links:t
#+TITLE: Setting up macOS for scientific computing and software development

Author: Matthias Cuntz, mc (at) macu (dot) de\\
Modified: 03.05.2024

Inspired by guides of [[https://medium.com/faun/zero-to-hero-set-up-your-mac-for-software-development-919ede3df83b][Dirk Avery]], [[https://medium.com/better-programming/setting-up-your-mac-for-web-development-in-2020-659f5588b883][Vinicius De Antoni]], [[https://sourabhbajaj.com/mac-setup/][Sourabh Bajaj]], [[https://github.com/nicolashery/mac-dev-setup][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.

* Table of Contents :TOC:
- [[#how-to-update-the-os][How to update the OS]]
- [[#update-via-software-update][Update via /Software Update/]]
- [[#setup-macos][Setup macOS]]
- [[#check-for-system-updates][Check for system updates]]
- [[#xcode][Xcode]]
- [[#set-preferences-of-macos-and-standard-apps][Set preferences of macOS and standard apps]]
- [[#set-the-default-shell][Set the default shell]]
- [[#app-store][App Store]]
- [[#xquartz][XQuartz]]
- [[#homebrew][Homebrew]]
- [[#set-your-default-shell-2][Set your default shell #2]]
- [[#homebrew-2][Homebrew #2]]
- [[#emacs][Emacs]]
- [[#latex][LaTeX]]
- [[#freeware][Freeware]]
- [[#myriad-pro][Myriad Pro]]
- [[#python][Python]]
- [[#locate][locate]]
- [[#payware][Payware]]
- [[#additional-software][Additional software]]
- [[#netcdf4underfortran-and-openmpi-development-packages][netcdf4\under{}fortran and openmpi development packages]]

* How to update the OS
There are basically two options:
1. Reformat the startup disk and install a fresh new system, or

1. Use /Software Update/ to update macOS on top of the existing OS.

In both cases, a little bit of preparation helps. I do not use the first option anymore. It is covered in earlier versions of this document such as in README14.org.

** Update via /Software Update/

*** Before starting
1. It is always recommended to make a backup of your system before an upgrade.

1. Update all your installed apps in /Applications/. The newest versions of the applications will probably already be suitable for the new macOS version. It avoids the problem that you cannot open anymore the old version of the application on the new macOS just to do the update. You'd then have to uninstall/install the application again, which might need the licence key, etc.

For this, open each non-Apple application and /Check for Updates.../.

Use the /App Store.../ for all Apple programs and apps downloaded from the App Store..

1. The /Software Update/ takes care of all your accounts, passwords, etc. The step before takes care of all the installed applications. But anything installed from the command line will (most probably) not work anymore. So I first uninstall all the things that will be installed in the steps below, which are Homebrew (including the installed casks), LaTeX, Python/pyenv, and everything installed with install\under{}netcdf. I also first set back Apple's bash shell as default because the newer bash shell used until now is removed together with Homebrew and you run into trouble if it is still set as your default shell afterwards.

Set Apple's bash shell as default:

#+BEGIN_SRC bash
chsh -s /bin/bash
#+END_SRC

You have to open a new login terminal that it takes effect.

Check the casks installed with Homebrew. This might not work anymore because you changed the shell, e.g. to /zsh/. Then copy the box below that sets the /HOMEBREW_PREFIX/ into this new login terminal ([[#homebrew][Homebrew]]).

#+BEGIN_SRC bash
brew list --casks
#+END_SRC

Best to note them somewhere (basictex font-source-code-pro emacs motrix panoply quarto temurin).

Uninstall all casks (you might have to type your password several times for this if not even for each casks):

#+BEGIN_SRC bash
for c in $(brew list --casks) ; do brew uninstall ${c} ; done
#+END_SRC

Remove Homebrew (password needed):

#+BEGIN_SRC bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
#+END_SRC
#+BEGIN_SRC bash
[[ -f ${HOME}/.fzf.bash ]] && rm -f ${HOME}/.fzf.bash
#+END_SRC
#+BEGIN_SRC bash
[[ -f ${HOME}/.fzf.zsh ]] && rm -f ${HOME}/.fzf.zsh
#+END_SRC
#+BEGIN_SRC bash
[[ -d /opt/homebrew ]] && sudo rm -r /opt/homebrew
#+END_SRC

Remove (remnants of) LaTeX:

#+BEGIN_SRC bash
sudo rm -r /usr/local/texlive/
#+END_SRC
#+BEGIN_SRC bash
sudo rm -r /Library/TeX/
#+END_SRC

Remove pyenv's Python versions:

#+BEGIN_SRC bash
rm -rf ${HOME}/.pyenv
#+END_SRC

Remove everything under =/usr/local=. This seems extreme but Apple has nothing installed under =/usr/local=, so it comes all from you or Homebrew. You might change into =/usr/local= and remove selected directories by hand. For example, our virus scanner at work installs its uninstall-script in =/usr/local=.

#+BEGIN_SRC bash
rm -rf /usr/local/*
#+END_SRC

*** Installing macOS via /Software Update/

Go to /System Preferences/ > /Software Update/ (macOS <= 12) or to /System Settings/ > /General/ > /Software Update/ (macOS >= 13). Select to install the new macOS and follow the on-screen instructions.

* Setup macOS
The steps are intended to be done (roughly) in order. You have to open new login shells several times during the process. If something does not work after installation, opening a new login shell might do the trick.

** Check for system updates
Check for updates of macOS in /System Preferences/ > /Software Update/ (macOS <= 12) or /System Settings/ > /General/ > /Software Update/ (macOS >= 13).

** 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. Note that installing the full XCode takes considerable time (count rather half an hour or more).

The normal way to install the XCode Command Line Tools (CLT) from the terminal would be:

#+BEGIN_SRC bash
xcode-select --install
#+END_SRC

There was a glitch (in macOS 13 Ventura) if you installed with /Software Update/ and had a full XCode installation: the XCode Command Line Tools did not get updated so that gfortran, for example, clashes with XCode's clang compiler. So I first uninstalled CLT and reinstalled them again:

#+BEGIN_SRC bash
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
#+END_SRC

On macOS 14 Sonoma, this prints /xcode-select: note: install requested for command line developer tools/
and you have to open /Software Update/ again to install the command line tools.

This still pointed to the compiler within the XCode app:

#+BEGIN_SRC bash
xcode-select --print-path
# /Applications/Xcode.app/Contents/Developer/
#+END_SRC

This can be [[https://stackoverflow.com/questions/72428802/c-lang-llvm-option-parsing-unknown-command-line-argument-when-running-gfort][fixed]] by pointing to clang within the CLT:

#+BEGIN_SRC bash
sudo xcode-select -switch /Library/Developer/CommandLineTools
#+END_SRC

You might let Homebrew do the job, i.e. it will install the XCode Command Line Tools if they are missing.

The 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. If you install Xcode, it is reasonable to complete the Xcode installation and the one-time opening before starting with [[#homebrew][Homebrew]]. Otherwise, it might install the command line tools CLT twice, but it costs only download bandwidth and time.

While waiting for XCode to install, you can download and install the other apps from [[#app-store][App Store]], [[#xquartz][XQuartz]] and some [[#freeware][Freeware]] except [[http://www.chachatelier.fr/latexit/][LaTeXiT]] and [[https://www.sourcetreeapp.com][SourceTree]]. You can also [[#set-preferences-of-macos-and-standard-apps][Set preferences of macOS and standard apps]].

** Set preferences of macOS and standard apps
Set /System Preferences/ (macOS <= 12) or /System Settings/ (macOS >= 13) such as:
Check for updates of macOS in /System Preferences/ > /Software Update/ (macOS <= 12) or /System Settings/ > /General/ > /Software Update/ (macOS >= 13) .

- Set computer name in /Sharing/ > /Computer Name/ or in /General/ > /Sharing/ > /Local hostname/

- Unset all in /Mission Control/ or in /Desktop & Dock/ > /Mission Control/

- Set /Keyboard/ > /Modifier Keys.../ > /Caps Lock Key/ to /No Action/ or set /Keyboard/ > /Keyboard Shortcuts/ > /Modifier Keys/ > /Caps Lock Key/ to /No Action/

Set preferences/settings in standard macOS apps such as:
- Terminal
+ Set /Profiles/ > /Shell/ > /When the shell exists:/ to /Close if the shell exited cleanly/

+ Unset tickbox /Profiles/ > /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:

#+BEGIN_SRC bash
chsh -s /bin/bash
#+END_SRC

To 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=:

#+BEGIN_SRC bash
export BASH_SILENCE_DEPRECATION_WARNING=1
#+END_SRC

My current =.bash_profile= is as dot-bash\under{}profile in this repository along with the two sub-config files =.bashrc= as dot-bashrc for general aliases and functions and =.bashrc.15= as dot-bashrc.15 for macOS 15 Sequoia-specific aliases and functions.

** App Store
Even when you installed using /Software Update/, you should check for updates. Do not look only in /App Store.../ > /Updates/ but also on your account (on the bottom left) if there is an update. Xcode did not show up in /Updates/ for me but I had to update it from the account page.

** XQuartz
XQuartz is the X-window system running on macOS, needed for \ast{}nix GUI programs. Get it from [[http://xquartz.macosforge.org/][XQuartz]].

** Homebrew
Install [[http://brew.sh][Homebrew]] for easy \ast{}nix package installation.

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

This installs Homebrew into =/usr/local= on macOS Intel and into =/opt/homebrew= on macOS Apple Silicon (M1, M2, etc.).

You might want to put into your =.bash_profile= for macOS Intel:

#+BEGIN_SRC bash
[[ -x $(which brew) ]] && eval $(brew shellenv)
#+END_SRC

and for macOS Apple Silicon (Mx):

#+BEGIN_SRC bash
[[ -d /opt/homebrew ]] && eval $(/opt/homebrew/bin/brew shellenv)
#+END_SRC

so that Homebrew can be found. This sets, for example, the environment variables =HOMEBREW_PREFIX=, =HOMEBREW_CELLAR=, and =HOMEBREW_REPOSITORY= and prepends the =$PATH= with Homebrew's bin directory. I set this manually because I want to have Homebrew's bin directory at the end rather than at the beginning of the system =$PATH= such as:

#+BEGIN_SRC bash
if [[ -d /opt/homebrew ]] ; then
# eval $(/opt/homebrew/bin/brew shellenv)
# or by hand to append rather than prepand path
export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
export PATH=${PATH}:/opt/homebrew/bin
elif [[ -e /usr/local/bin/brew ]] ; then
export HOMEBREW_PREFIX="/usr/local";
export HOMEBREW_CELLAR="/usr/local/Cellar";
export HOMEBREW_REPOSITORY="/usr/local";
export PATH=${PATH}:/usr/local/bin
fi
#+END_SRC

** 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:

#+BEGIN_SRC bash
brew install bash
#+END_SRC
#+BEGIN_SRC bash
# add the following line to /etc/shells
# /usr/local/bin/bash
# or
# /opt/homebrew/bin/bash
sudo nano /etc/shells
#+END_SRC
#+BEGIN_SRC bash
chsh -s ${HOMEBREW_PREFIX}/bin/bash
#+END_SRC

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 shell scripts is to use =#!/usr/bin/env bash= as your shebang. This will take the first /bash/ in your =$PATH=, which would now be =/usr/local/bin/bash= or =/opt/homebrew/bin/bash=.

You can now use /bash-completion/ with the new bash shell.

#+BEGIN_SRC bash
brew install bash-completion@2
#+END_SRC

You then have to put the following lines in your =.bash_profile= to use bash-completion:

#+BEGIN_SRC bash
if [[ -f "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]] ; then
export BASH_COMPLETION_COMPAT_DIR="${HOMEBREW_PREFIX}/etc/bash_completion.d"
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
fi
#+END_SRC

Note that these lines have to be after the sourcing of =.fzf.bash= in your =.bash_profile= if you installed /fzf/, otherwise you get an error such as =programmable_completion: source: possible retry loop=.

You can do the exact same steps for the zsh shell. Apples version of /zsh/ 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 [[https://ohmyz.sh][Oh My ZSH]] for easy configuration of /zsh/.

After a system update such as from /System Preferences/ > /Software Update/, there might be a link =Relocated Items/= on your Desktop pointing to =/Users/Shared/Relocated Items=. This is a copy of the changed =/etc/shells=. As long as Apple does not modify =/etc/shells= during an update, the edited version stays untouched, though. One can safely delete the link on the Desktop and also the directory under =/Users/Shared=. It does not hurt to do a =cat /etc/shells= in the terminal before, checking that your edits are still there.

** Homebrew #2

- *GNU compiler and netCDF software*

The gcc suite includes /gfortran/. /make/ is the build system of various software packages.
Install /nco/, /ncview/, and /Panoply/ to work with and visualise netCDF files. This installs the netcdf-C version, which comes with /ncdump/, etc. Homebrew had netcdf-C, netcdf-C++, and netcdf-Fortran bundled in /netcdf/ before. They are individual packages now. /netcdf/ installs the netcdf-C package only. See install\under{}netcdf below for Fortran support.

#+BEGIN_SRC bash
brew install gcc
#+END_SRC
#+BEGIN_SRC bash
brew install cmake
#+END_SRC
#+BEGIN_SRC bash
# geos and gdal take considerable time to install
for i in geos gdal nco ncview ; do brew install ${i} ; done
#+END_SRC
#+BEGIN_SRC bash
brew install cdo
#+END_SRC
#+BEGIN_SRC bash
brew install --cask temurin # Java, for panoply
#+END_SRC
#+BEGIN_SRC bash
brew install --cask panoply
#+END_SRC

/HDF5/ from Homebrew is not thread-safe so /cdo/ will need the -L flag if piping, i.e. more than one operator is given to /cdo/ in one call such as =cdo -timmean -selvar,Tair infile outfile=. I use in my =.bashrc=:

#+BEGIN_SRC bash
alias cdo="cdo -L"
#+END_SRC

Note that =cdo -L= instead of purely =cdo= must also be used in scripts for piping.

- *Install more practical software*

Some more practical software such as, /fd/ for a faster find, /ripgrep/ for grepping across a directory tree, the statistical computing environment /R/, the version control system /subversion/, and the command-line fuzzy finder /fzf/, and the tldr implementation /tealdeer/ for more concise help pages:

#+BEGIN_SRC bash
brew install htop # dynamic real-time information of running processes
#+END_SRC
#+BEGIN_SRC bash
brew install tree # visualise folder tree structure
#+END_SRC
#+BEGIN_SRC bash
brew install fd # faster find
#+END_SRC
#+BEGIN_SRC bash
brew install bat # cat with syntax highlighting
#+END_SRC
#+BEGIN_SRC bash
brew install ripgrep # grep across directory tree
#+END_SRC
#+BEGIN_SRC bash
brew install fzf # command-line fuzzy finder
#+END_SRC
#+BEGIN_SRC bash
brew install wget # retrieve files from web servers
#+END_SRC
#+BEGIN_SRC bash
brew install tealdeer # simples help pages for command-line tools
#+END_SRC
#+BEGIN_SRC bash
brew install ghostscript # postscript and pdf language interpreter
#+END_SRC
#+BEGIN_SRC bash
brew install enscript # convert text files to postscript files
#+END_SRC
#+BEGIN_SRC bash
brew install imagemagick # image manipulations
#+END_SRC
#+BEGIN_SRC bash
brew install ffmpeg # for movies
#+END_SRC
#+BEGIN_SRC bash
brew install pandoc # convert between markup languages
#+END_SRC
#+BEGIN_SRC bash
brew install pkg-config # reveal details of installed libraries
#+END_SRC
#+BEGIN_SRC bash
brew install graphviz doxygen # documentation for programming languages
#+END_SRC
#+BEGIN_SRC bash
brew install subversion # version control system
#+END_SRC
#+BEGIN_SRC bash
brew install git # version control system
#+END_SRC
#+BEGIN_SRC bash
brew install rsync # better Unicode support in newer rsync versions
#+END_SRC
#+BEGIN_SRC bash
brew install r # statistical computing environment
#+END_SRC
#+BEGIN_SRC bash
brew install --cask quarto # jupyter/Rmarkdown like notebooks in markdown
#+END_SRC
#+BEGIN_SRC bash
brew install --cask motrix # download manager
#+END_SRC

And some installations of the helpers:

#+BEGIN_SRC bash
${HOMEBREW_PREFIX}/opt/fzf/install
#+END_SRC
#+BEGIN_SRC bash
tldr --update
#+END_SRC

I also set =${HOME}/.tealdeer= as my configuration directory for /tealdeer/ in =.bash_profile=,

#+BEGIN_SRC bash
export TEALDEER_CONFIG_DIR=${HOME}/.tealdeer
#+END_SRC

and get a standard config file =${HOME}/.tealdeer/config.toml= that I edit to tailor to my taste:

#+BEGIN_SRC bash
tldr --seed-config
#+END_SRC

** Emacs
I used to use [[http://aquamacs.org][Aquamacs]], then used [[https://www.spacemacs.org][Spacemacs]], and then tried a few other setups ([[https://github.com/doomemacs/doomemacs][doom]], [[https://github.com/angrybacon/dotemacs][dotemacs]], [[https://codeberg.org/kngwyu/boremacs][boremacs]], [[https://github.com/abougouffa/minemacs][minemacs]], etc.). Now I am using my own setup by copy/paste different bits from the other setups. My current setup is in =dot-emacs.d= in this repository.

I install Emacs with Homebrew:

#+BEGIN_SRC bash
brew install --cask emacs
#+END_SRC

Coming from another Emacs, backup =.emacs= and =.emacs.d=:

#+BEGIN_SRC bash
cd ${HOME}
if [[ -f .emacs ]] ; then mv .emacs .emacs.bak ; fi
if [[ -d .emacs.d ]] ; then mv .emacs.d .emacs.d.bak ; fi
#+END_SRC

Then I install my setup by copying it to =~/.emacs.d=.

I use the font [[https://github.com/adobe-fonts/source-code-pro][Source Code Pro]] that is also used in Spacemacs, install aspell for spell checking, and [[https://github.com/astral-sh/ruff][ruff]] for linting Python code:

#+BEGIN_SRC bash
brew install --cask font-source-code-pro
#+END_SRC
#+BEGIN_SRC bash
brew install aspell
#+END_SRC
#+BEGIN_SRC bash
brew install ruff
#+END_SRC

If you open the new Emacs for the first time, it will install and byte-compile some packages. This might take some time.

** LaTeX
One can download LaTeX from [[https://tug.org/mactex/][MacTeX]] or use a Homebrew cask. I have chosen Homebrew's cask this time because I use the BasicTeX installation and I let Homebrew handle the update between years (=brew upgrade --cask basictex=), which is always a hassle otherwise.

#+BEGIN_SRC bash
brew install --cask basictex
#+END_SRC

If you chose BasicTeX, then install immediately a few LaTeX packages, which I encountered during different projects:

#+BEGIN_SRC bash
sudo tlmgr update --self ; \
sudo tlmgr install \
a0poster a4wide acronym adjustbox algorithmicx \
algorithms anyfontsize apacite appendix arydshln \
biber biblatex biblatex-apa biblatex-chicago \
bigfoot blindtext boondox breakurl capt-of changepage \
changes chemfig cleveref cmbright collectbox \
collection-fontsrecommended collection-fontutils comment \
cormorantgaramond csquotes dinbrief doi doublestroke \
draftwatermark dvipng easy elsarticle enumitem \
environ etoolbox everypage floatflt floatrow fltpoint \
fncychap fontawesome5 fontaxes fontinst footmisc \
framed gensymb german glossaries glossaries-extra \
gradientframe helvetic hyphenat ifmtarg kastrup \
lastpage latexmk lettrine lineno lipsum \
listingsutf8 makecell marginnote mdframed mdsymbol \
mhchem minitoc mnsymbol moreverb multirow mwe \
ncctools needspace newtx nomencl ntheorem pbox \
pdfcol pdfcrop pgf pgfgantt placeins preprint program psnfss \
regexpatch sectsty sidecap simplekv siunitx soul \
stmaryrd sttools subfigure subfiles supertabular \
tabfigures tabulary tcolorbox textpos threeparttable \
tikzfill titlesec titling todonotes truncate type1cm \
ucs ulem units varwidth vruler wallpaper was wasy \
wasysym wrapfig xcolor xifthen xkeyval xstring \
arev bera fira iwona kurier lato ly1 mathastext newtxsf \
opensans psnfss sansmathfonts sfmath sourcesanspro
#+END_SRC

I also install LaTeXML so that Emacs' org-mode can convert LaTeX equations to MathML on export:

#+BEGIN_SRC bash
brew install latexml
#+END_SRC

** Freeware
Some essential Freeware for me:
- [[http://www.freemacsoft.net/appcleaner/][AppCleaner]], for removing apps and all their traces,

- [[https://acrobat.adobe.com/us/en/acrobat/pdf-reader.html][Adobe Reader]], because Preview has problems with some PDFs,

- [[https://www.mozilla.org/en-US/firefox/all/][Firefox Developer Edition]], Safari is not always supported. [[https://www.google.com/chrome/][Chrome]] is probably the most supported browser. I sometimes also use [[https://www.opera.com][Opera]],

- [[http://www.chachatelier.fr/latexit/][LaTeXiT]], exporting LaTeX equations as graphics,

- [[https://rectangleapp.com][Rectangle]], moving windows with keystrokes,

- [[https://www.zotero.org][Zotero]], reference manager,

- [[http://www.skype.com/en/][Skype]], video calls, I still use it,

- [[https://www.sourcetreeapp.com][SourceTree]], git GUI originally for bitbucket but works with other git repositories as well,

- [[https://www.spotify.com/][Spotify]], streaming music,

- [[http://www.videolan.org/vlc/][VLC]], video player for all formats,

- [[https://github.com/markummitchell/engauge-digitizer][Engauge Digitizer]], recover data points from graphs.

** 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:

#+BEGIN_SRC bash
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.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
#+END_SRC

** Python

macOS Catalina (10.15) still came 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. From macOS Big Sur (11.5) onwards, macOS comes with Python 3 (from macOS 13 Ventura, is is actually part of the XCode command line tools). But I still recommend to install Python with /pyenv/ and /pyenv-virtualenv/: you can install different Python versions, use different virtual environments in different directories (projects) very easily, etc.

Installation of Python versions can be a real mess at times, as noted by [[https://xkcd.com/1987/][XKCD]]:

#+ATTR_HTML: :alt Python path on my system :align center :width 300 :height 300
[[https://imgs.xkcd.com/comics/python_environment.png]]

/pyenv/ and /pyenv-virtualenv/ makes that very easy: see the great article [[https://medium.com/faun/pyenv-multi-version-python-development-on-mac-578736fb91aa][pyenv: Multi-version Python development on Mac]] by Dirk Avery.

To install pyenv with Homebrew:

#+BEGIN_SRC bash
brew install openssl readline sqlite3 xz zlib
brew install pyenv
brew install pyenv-virtualenv
#+END_SRC

You have to set the following in your =.bash_profile= so that the shell always finds the currently chosen Python version as the first entry.

#+BEGIN_SRC bash
export PYENV_ROOT="${HOME}/.pyenv"
export PATH=${PYENV_ROOT}/shims:${PATH}
if command -v pyenv 1>/dev/null 2>&1 ; then eval "$(pyenv init -)" ; fi
if command -v pyenv virtualenv-init 1>/dev/null 2>&1 ; then eval "$(pyenv virtualenv-init -)" ; fi
#+END_SRC

Note that the =$PATH= environment must be prepended with =${PYENV_ROOT}/shims= and not =${PYENV_ROOT}/bin= as given in the (older) user guide. Also, this has to be done /after/ the addition of Homebrew to the system =$PATH= so that the pyenv Python installation can be found first; otherwise Homebrew's Python will be found first.

- *pyenv and pyenv-virtualenv 101*

After starting a new shell, for example by doing =exec ${SHELL}=, you can start installing and using different Python versions (but see my installation below):

#+BEGIN_SRC bash
pyenv install --list
pyenv install 3.13.1
pyenv global 3.13.1
#+END_SRC

Try to rehash first if a problem occurs with /pyenv/: =pyenv rehash=. For example, some new Homebrew packages might upgrade /pyenv/ as well. Then you get an error such as:

#+BEGIN_SRC bash
/Users/cuntz/.pyenv/shims/python: line 21:
/usr/local/Cellar/pyenv/2.3.12/libexec/pyenv:
No such file or directory
#+END_SRC

=pyenv rehash= resolves the issue.

Note that I actually install Python versions currently as follows:

#+BEGIN_SRC bash
# most probably already installed
brew install openssl readline sqlite3 xz zlib tcl-tk@8
#+END_SRC
#+BEGIN_SRC bash
env LDFLAGS=" \
-L$(brew --prefix openssl)/lib \
-L$(brew --prefix readline)/lib \
-L$(brew --prefix sqlite3)/lib \
-L$(brew --prefix xz)/lib \
-L$(brew --prefix zlib)/lib \
-L$(brew --prefix tcl-tk@8)/lib" \
CPPFLAGS=" \
-I$(brew --prefix openssl)/include \
-I$(brew --prefix readline)/include \
-I$(brew --prefix sqlite3)/include \
-I$(brew --prefix xz)/include \
-I$(brew --prefix zlib)/include \
-I$(brew --prefix tcl-tk@8)/include" \
PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig:$(brew --prefix readline)/lib/pkgconfig:$(brew --prefix sqlite3)/lib/pkgconfig:$(brew --prefix xz)/lib/pkgconfig:$(brew --prefix zlib)/lib/pkgconfig:$(brew --prefix tcl-tk@8)/lib/pkgconfig" \
PYTHON_CONFIGURE_OPTS=" \
--enable-optimizations" \
pyenv install 3.13.1
#+END_SRC

This uses the newer Tcl/Tk version 8.6 from Homebrew for /tkinter/ (but not v9.0) and turns on profile guided optimization as well as link time optimization for Python, being then about 10% faster than without optimization. Optimization takes significantly more time to install Python. If you do not use /tkinter/ and just want to try out a Python version, =pyenv install 3.13.1= is just fine. Otherwise I recommend the optimization because you do not install Python too often but get a significant gain.

Virtual environments are then created as:

#+BEGIN_SRC bash
pyenv virtualenv 3.13.1 mypy
#+END_SRC

The virtual environment /mypy/ can then be used just as any installed Python version with /pyenv/. For example, use virtual environment /mypy/ in the current shell:

#+BEGIN_SRC bash
pyenv activate mypy
#+END_SRC

Or always use /mypy/ in the current directory:

#+BEGIN_SRC bash
pyenv local mypy
#+END_SRC

/pyenv/ provides also /anaconda/, /miniconda/, /miniforge/, etc. with which you can use conda environments:

#+BEGIN_SRC bash
pyenv install miniforge3-latest
pyenv global miniforge3-latest
pyenv virtualenv mypy
#+END_SRC

You can then install (conda, mamba, and pip) packages in the project:

#+BEGIN_SRC bash
conda install numpy scipy matplotlib-base
#+END_SRC

If git tells /gettext not found/ after installing anaconda/miniconda, see [[https://github.com/nicolashery/mac-dev-setup][Nicolas Hery]].

- *Essential Python packages*

Anaconda comes with hundreds of packages. I tend to use a Python version with pyenv or miniforge and install my essential packages with /pip/ or /conda/mamba/. These are currently in my main environment:\\
numpy, scipy, matplotlib, cartopy, ipython, jupyter, pandas, cftime, netcdf4, statsmodels, scikit-learn, xlrd, openpyxl, mpi4py, schwimmbad, xarray, numpydoc, pytest, pytest-cov, gdal, f90nml, pykdtree, cython, pyshp, six, wheel, sphinx, sphinx_book_theme

and mostly this subset in other virtual environments:\\
numpy, scipy, matplotlib, pandas, netcdf4, xarray, ipython, wheel

There is/was a problem with Apple's Accelerate framework on Apple Silicon (M1/2) so that one should use /OpenBLAS/. You also need to tell /pip/ where to find the HDF5 library and the GEOS library and the like. You do not need the lines with =OPENBLAS= and =HDF5-DIR= if you are on macOS on Intel and Homebrew installs into =/usr/local=; this directory is searched automatically. Here I install my standard python virtual environment (pystd):

#+BEGIN_SRC bash
# essential subset
if [[ "$(uname -m)" == "arm64" ]] ; then
export OPENBLAS="$(brew --prefix openblas)"
export HDF5_DIR="$(brew --prefix hdf5)"
export GEOS_DIR="$(brew --prefix geos)"
export GEOS_CONFIG="$(brew --prefix geos)/bin/geos-config"
fi
#+END_SRC
#+BEGIN_SRC bash
pyenv virtualenv 3.13.1 pystd
pyenv global pystd
#+END_SRC
#+BEGIN_SRC bash
# test if install works
python -m pip install numpy
#+END_SRC
#+BEGIN_SRC bash
for i in wheel scipy matplotlib ipython pandas cftime netcdf4 \
xarray ipython ; do \
python -m pip install ${i} ; done
#+END_SRC
#+BEGIN_SRC bash
# other standard packages
for i in jupyter statsmodels scikit-learn schwimmbad \
numpydoc pytest pytest-cov f90nml pykdtree cython pyshp six \
xlrd openpyxl ; do \
python -m pip install ${i} ; done
#+END_SRC
#+BEGIN_SRC bash
# other developping packages
for i in sphinx sphinx_book_theme ; do \
python -m pip install ${i} ; done
#+END_SRC
#+BEGIN_SRC bash
# shapely and gdal for cartopy
# shapely needs to be built from source to link to geos.
# Uninstall it if already installed
[[ -z $(python -m pip freeze | grep shapely) ]] && \
python -m pip uninstall -y shapely
python -m pip install shapely --no-binary shapely
#+END_SRC
#+BEGIN_SRC bash
# gdal needs to know the installed gdal version
# and install numpy-based raster support
# test: python3 -c 'from osgeo import gdal_array'
pip install --no-cache --force-reinstall gdal[numpy]=="$(gdal-config --version).*"
#+END_SRC
#+BEGIN_SRC bash
python -m pip install cartopy
# basemap is back in development again :-)
# but does not work with Python 3.12 yet :-(
# python -m pip install basemap-data
# python -m pip install basemap-data-hires
# python -m pip install basemap
# mpi4py will be installed after installing openmpi later
#+END_SRC

** locate
Create locate database so that you can search files with the locate command:

#+BEGIN_SRC bash
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
#+END_SRC

This might already be running (/Operation already in progress/ or /Load failed: 5: Input//output error/).

** Payware
Install Payware, which is for me:
- Microsoft Office,

- [[https://www.antidote.info/en][Antidote]], spell and grammar checker for English and French,

- [[http://www.nag.co.uk/downloads/npdownloads.asp][NAG compiler]], very meticulous Fortran compiler,

- [[https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html][Intel oneAPI Base Toolkit]] and [[https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html][Intel oneAPI HPC Toolkit]], C/C++/Fortran compiler producing very fast code,

- [[https://www.cyberghostvpn.com/][CyberGhost]], VPN client,

** Additional software
Install additional software from you institution or similar such as VPN clients, cloud services, etc. For INRAE this is: WithSecure Antivirus, GlobalProtect VPN, StorageMadeEasy.

** netcdf4\under{}fortran and openmpi development packages
You can install [[https://downloads.unidata.ucar.edu/netcdf/][netcdf-fortran]] for the gfortran compiler.

#+BEGIN_SRC bash
brew install netcdf-fortran
#+END_SRC

This will automatically update netcdf-fortran for gfortran if a newer version of netcdf-C and/or netcdf-fortran becomes available.

However, if you use other Fortran compilers as well, you might want to use the script [[https://github.com/mcuntz/install_netcdf][install\under{}netcdf]] to install it and not flood your namespace with different versions of =netcdf.mod=, etc. The script [[https://github.com/mcuntz/install_netcdf][install\under{}netcdf]] installs netcdf-fortran, openmpi, and/or mpich development packages for different Fortran compilers. The script is well documented and we just describe the general steps.

- Look for the latest versions (numbers) of [[https://downloads.unidata.ucar.edu/netcdf/][netcdf-fortran]], [[https://www.open-mpi.org][openmpi]], and/or [[http://www.mpich.org/downloads/][mpich]] (addresses are also given at the beginning of the script) and set them below /donetcdf4\under{}fortran/, /doopenmpi/, and/or /dompich/.

- Set /donetcdf4\under{}fortran/, /doopenmpi/, and/or /dompich/ to 1.

- Check that ~prefix=/usr/local~.

- Set Fortran compiler, e.g. ~fortran_compilers="gfortran"~.

- For Intel, you need to source the compiler setup script such as:

#+BEGIN_SRC bash
source /opt/intel/bin/compilervars.sh intel64
#+END_SRC

- For PGI, you also have to set the ~PGIPATH~.

- Run the script on the command line and give your sudo password if you install into ~prefix=/usr/local~.

After having installed /openmpi/, one can also install /mpi4py/ in Python, for example:

#+BEGIN_SRC bash
env MPICC=/usr/local/openmpi-4.1.7-gfortran/bin/mpicc python -m pip install mpi4py
#+END_SRC

However, homebrew upgrades also netcdf-C to newer versions if you install or update a package that depends on it. Then the netcdf-fortran package installed with install\under{}netcdf will not work anymore (it will link to the old, uninstalled C version) and you have to rerun the script [[https://github.com/mcuntz/install_netcdf][install\under{}netcdf]] with /donetcdf4\under{}fortran=1/ and ~fortran_compilers="gfortran"~. I still do it this way to minimize conflicts between different Fortran compilers; and re-installing netcdf-fortran with install\under{}netcdf is very fast.