Mac users
Contents
Mac users#
Choosing a Unix shell#
The Unix shell (Unix command line interface) comes in a few different versions, with bash
and zsh
being among the most widely used. Most commands are identical across different shells, but in some cases there are small differences. One example is commands that use wildcards like *
, where zsh
might require you to add quotation marks around the command arguments, or “escape” the wildcard by writing \*
instead of *
.
The commands listed on our course pages have generally been tested on bash
, which is the default shell on Ubuntu Linux. It was also the default on Mac until macOS 10.15 Catalina, when Mac switched to use zsh
as default.
To see which shell you are currently running, open a terminal and run the command
echo $0
This will give the path to the shell you are running, which will probably be /bin/bash
or /bin/zsh
.
It’s easy to change the default shell – have a look here for point-and-click instructions, or simply run the command
chsh -s /bin/bash
to set bash
as default, or run
chsh -s /bin/zsh
to set zsh
as default. Note that you probably have to close and restart your terminal for this change to take effect.
If you want to switch shell just for your current terminal session, rather than setting a new default, you can do that simply by running
zsh
or
bash
Installation of basic software#
Installation of software for C++ can be a little bit of a hassle on macOS. Here we’ll try to walk you through the process, step-by-step.
First, install Xcode from the app store. This contains the basic building blocks we need. It installs Git and Make, as well as a few other command line tools. (Note that Xcode unfortunately is a very large package – over 12 GBs, and may even require substantially more available disk space than this for the installation.)
Now we’ll install a package manager which we’ll use to install many other packages. Go to Homebrew and follow the installation instructions there. It’s easy, just copy the command they provide there and run it in your terminal.
Now, run the following command in your terminal to install some additional C++ libraries we’ll use (Armadillo and OpenMP).
brew install armadillo libomp
Additional setup for M1 Mac users#
If your Mac is sufficiently new (since late 2020), then you might have a so-called “M1 Mac”, that is a Mac based on the Apple M1 processor. (An alternative name for these processors is “Apple silicon”.) Older Macs are based on Intel processors.
To check if you have an M1-based or Intel-based Mac, click the Apple logo in the top-left corner, select “About This Mac”, and see what it says under “Chip”. (See an example here.)
Homebrew uses a different default installation directory on M1 Macs compared to on the older Intel-based Macs. So in order for the C++ compiler to find the Armadillo library, you must copy the installed files to the correct directory.
First, check which version of Armadillo that Homebrew installed on your system by listing the content of the directory /opt/homebrew/Cellar/armadillo
:
ls /opt/homebrew/Cellar/armadillo
Here you should see a directory with the version number, e.g. 10.6.2
or 11.2.3_1
or similar. Now run the copy commands below, adjusted to use your Armadillo version number in the paths. For version 11.2.3_1
the commands are:
sudo cp -r /opt/homebrew/Cellar/armadillo/11.2.3_1/lib/* /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
sudo cp -r /opt/homebrew/Cellar/armadillo/11.2.3_1/include/armadillo* /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
Since we use sudo
here you will (probably) have to type in your password.
Install additional command line tools#
There’s a plethora of command line tools that can be useful. Here are some examples:
wget and curl are command line tools that allow you to download from the web using the command line.
htop is a powerful task manager that also displays the work each thread uses graphically in your terminal. This is a useful tool when your code is parallelized (later in the course) so that you can monitor the work each thread does.
tree is a convenient tool to display files and directories in the terminal.
To install these, simply run
brew install wget curl htop tree