Author: Matthias Cuntz, mc (at) macu (dot) de
Modified: 03.05.2024
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.
There are basically two options:
- Reformat the startup disk and install a fresh new system, or
- 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.
- It is always recommended to make a backup of your system before an upgrade.
- 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..
- 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_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:
chsh -s /bin/bashYou 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).
brew list --casksBest 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):
for c in $(brew list --casks) ; do brew uninstall ${c} ; done
Remove Homebrew (password needed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"[[ -f ${HOME}/.fzf.bash ]] && rm -f ${HOME}/.fzf.bash
[[ -f ${HOME}/.fzf.zsh ]] && rm -f ${HOME}/.fzf.zsh
[[ -d /opt/homebrew ]] && sudo rm -r /opt/homebrew
Remove (remnants of) LaTeX:
sudo rm -r /usr/local/texlive/sudo rm -r /Library/TeX/Remove pyenv’s Python versions:
rm -rf ${HOME}/.pyenvRemove 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/localand remove selected directories by hand. For example, our virus scanner at work installs its uninstall-script in/usr/local.rm -rf /usr/local/*
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.
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 updates of macOS in System Preferences > Software Update (macOS <= 12) or System Settings > General > Software Update (macOS >= 13).
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:
xcode-select --installThere 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:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --installOn 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:
xcode-select --print-path
# /Applications/Xcode.app/Contents/Developer/This can be fixed by pointing to clang within the CLT:
sudo xcode-select -switch /Library/Developer/CommandLineToolsYou 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. 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, XQuartz and some Freeware except LaTeXiT and SourceTree. You can also 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
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=1My current .bash_profile is as dot-bash_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.
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 is the X-window system running on macOS, needed for ∗nix GUI programs. Get it from XQuartz.
Install Homebrew for easy ∗nix package installation.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"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:
[[ -x $(which brew) ]] && eval $(brew shellenv)and for macOS Apple Silicon (Mx):
[[ -d /opt/homebrew ]] && eval $(/opt/homebrew/bin/brew shellenv)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:
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
fiApple 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
# or
# /opt/homebrew/bin/bash
sudo nano /etc/shellschsh -s ${HOMEBREW_PREFIX}/bin/bashNote 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.
brew install bash-completion@2You then have to put the following lines in your .bash_profile to use bash-completion:
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"
fiNote 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 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.
- 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_netcdf below for Fortran support.
brew install gccbrew install cmake# geos and gdal take considerable time to install for i in geos gdal nco ncview ; do brew install ${i} ; done
brew install cdobrew install --cask temurin # Java, for panoplybrew install --cask panoplyHDF5 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:alias cdo="cdo -L"
Note that
cdo -Linstead of purelycdomust 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:
brew install htop # dynamic real-time information of running processesbrew install tree # visualise folder tree structurebrew install fd # faster findbrew install bat # cat with syntax highlightingbrew install ripgrep # grep across directory treebrew install fzf # command-line fuzzy finderbrew install wget # retrieve files from web serversbrew install tealdeer # simples help pages for command-line toolsbrew install ghostscript # postscript and pdf language interpreterbrew install enscript # convert text files to postscript filesbrew install imagemagick # image manipulationsbrew install ffmpeg # for moviesbrew install pandoc # convert between markup languagesbrew install pkg-config # reveal details of installed librariesbrew install graphviz doxygen # documentation for programming languagesbrew install subversion # version control systembrew install git # version control systembrew install rsync # better Unicode support in newer rsync versionsbrew install r # statistical computing environmentbrew install --cask quarto # jupyter/Rmarkdown like notebooks in markdownbrew install --cask motrix # download managerAnd some installations of the helpers:
${HOMEBREW_PREFIX}/opt/fzf/installtldr --updateI also set
${HOME}/.tealdeeras my configuration directory for tealdeer in.bash_profile,export TEALDEER_CONFIG_DIR=${HOME}/.tealdeer
and get a standard config file
${HOME}/.tealdeer/config.tomlthat I edit to tailor to my taste:tldr --seed-config
I used to use Aquamacs, then used Spacemacs, and then tried a few other setups (doom, dotemacs, boremacs, 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:
brew install --cask emacsComing from another Emacs, backup .emacs and .emacs.d:
cd ${HOME}
if [[ -f .emacs ]] ; then mv .emacs .emacs.bak ; fi
if [[ -d .emacs.d ]] ; then mv .emacs.d .emacs.d.bak ; fiThen I install my setup by copying it to ~/.emacs.d.
I use the font Source Code Pro that is also used in Spacemacs, install aspell for spell checking, and ruff for linting Python code:
brew install --cask font-source-code-probrew install aspellbrew install ruffIf you open the new Emacs for the first time, it will install and byte-compile some packages. This might take some time.
One can download LaTeX from 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.
brew install --cask basictexIf you chose BasicTeX, then install immediately a few LaTeX packages, which I encountered during different projects:
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 sourcesansproI also install LaTeXML so that Emacs’ org-mode can convert LaTeX equations to MathML on export:
brew install latexmlSome 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 sometimes also use Opera,
- LaTeXiT, exporting LaTeX equations as graphics,
- Rectangle, moving windows with keystrokes,
- Zotero, reference manager,
- Skype, video calls, I still use it,
- SourceTree, git GUI originally for bitbucket but works with other git repositories as well,
- Spotify, streaming music,
- VLC, video player for all formats,
- Engauge Digitizer, recover data points from graphs.
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.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 FontPromacOS 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 XKCD:
pyenv and pyenv-virtualenv makes that very easy: see the great article pyenv: Multi-version Python development on Mac by Dirk Avery.
To install pyenv with Homebrew:
brew install openssl readline sqlite3 xz zlib
brew install pyenv
brew install pyenv-virtualenvYou have to set the following in your .bash_profile so that the shell always finds the currently chosen Python version as the first entry.
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 -)" ; fiNote 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):pyenv install --list pyenv install 3.13.1 pyenv global 3.13.1Try 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:/Users/cuntz/.pyenv/shims/python: line 21: /usr/local/Cellar/pyenv/2.3.12/libexec/pyenv: No such file or directorypyenv rehashresolves the issue.Note that I actually install Python versions currently as follows:
# most probably already installed brew install openssl readline sqlite3 xz zlib tcl-tk@8env 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
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.1is 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:
pyenv virtualenv 3.13.1 mypyThe 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:
pyenv activate mypyOr always use mypy in the current directory:
pyenv local mypypyenv provides also anaconda, miniconda, miniforge, etc. with which you can use conda environments:
pyenv install miniforge3-latest pyenv global miniforge3-latest pyenv virtualenv mypyYou can then install (conda, mamba, and pip) packages in the project:
conda install numpy scipy matplotlib-baseIf git tells gettext not found after installing anaconda/miniconda, see 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_themeand mostly this subset in other virtual environments:
numpy, scipy, matplotlib, pandas, netcdf4, xarray, ipython, wheelThere 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
OPENBLASandHDF5-DIRif 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):# 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
pyenv virtualenv 3.13.1 pystd pyenv global pystd# test if install works python -m pip install numpyfor i in wheel scipy matplotlib ipython pandas cftime netcdf4 \ xarray ipython ; do \ python -m pip install ${i} ; done
# 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
# other developping packages for i in sphinx sphinx_book_theme ; do \ python -m pip install ${i} ; done
# 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
# 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).*"
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
Create locate database so that you can search files with the locate command:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plistThis might already be running (Operation already in progress or Load failed: 5: Input//output error).
Install Payware, which is for me:
- Microsoft Office,
- Antidote, spell and grammar checker for English and French,
- NAG compiler, very meticulous Fortran compiler,
- Intel oneAPI Base Toolkit and Intel oneAPI HPC Toolkit, C/C++/Fortran compiler producing very fast code,
- CyberGhost, VPN client,
Install additional software from you institution or similar such as VPN clients, cloud services, etc. For INRAE this is: WithSecure Antivirus, GlobalProtect VPN, StorageMadeEasy.
You can install netcdf-fortran for the gfortran compiler.
brew install netcdf-fortranThis 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 install_netcdf to install it and not flood your namespace with different versions of netcdf.mod, etc. The script install_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 netcdf-fortran, openmpi, and/or mpich (addresses are also given at the beginning of the script) and set them below donetcdf4_fortran, doopenmpi, and/or dompich.
- Set donetcdf4_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:
source /opt/intel/bin/compilervars.sh intel64- 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:
env MPICC=/usr/local/openmpi-4.1.7-gfortran/bin/mpicc python -m pip install mpi4pyHowever, 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_netcdf will not work anymore (it will link to the old, uninstalled C version) and you have to rerun the script install_netcdf with donetcdf4_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_netcdf is very fast.