edit · print · PDF

Please note that all the SIEpedia's articles address specific issues or questions raised by IAC users, so they do not attempt to be rigorous or exhaustive, and may or may not be useful or applicable in different or more general contexts.

January-2024: With the release of IRAF v2.18, which runs natively on the new M1-M3 Macs with the ARM CPU, installing a Linux virtual machine is no longer necessary. See the NOIRLab IRAF website for installation and configuration instructions.

Installation of IRAF on macOS with Multipass and Ubuntu

July-2021: This guide has been revised. Many thanks are due to Beth Klein (UCLA), who tried the Multipass and PyRAF installation herself, and whose comments and suggestions helped to fix a few issues and improve this presentation.

It's possible to run IRAF on macOS Catalina through Ventura (which do not allow any longer 32-bit executables to run), using a lightweight Ubuntu virtual machine installed with Multipass. Here we describe the installation procedure.

Multipass - installation

Multipass allows the installation of Ubuntu on macOS (and on Windows as well). It's a lightweight virtual machine with which you can run Ubuntu alongside macOS. The installation process is quite easy. Our specific purpose is to run IRAF/PyRAF in a Mac with Catalina or higher version, where part of IRAF can not run natively due to the lack of support for 32bit executables. Our experience with running IRAF/PyRAF this way has been very good.

To install Multipass go to https://multipass.run/, download the package and install it. Then, you can use the multipass command from the terminal window. To list all available commands type multipass --help, while detailed help on a specific command can be obtained by typing multipass help command_name, for instance multipass help exec

Install Ubuntu 22.04

First we find what images are available
multipass find

We decide to install Ubuntu 22.04, the latest LTS release. By default, the installed Ubuntu machine will have 5 GB of space and 1 GB of RAM, thus we want to increase it:
multipass launch --name ubuntu2204-25GB --disk 25G --mem 4G lts
"lts" is the name for Ubuntu 22.04 LTS as shown by multipass find. We give a mnemonic name to the virtual machine, to help identify it (you can install multiple virtual machines, each with its own configuration).

As we plan to have all our data in a directory on the Mac hard drive, and share it with the Ubuntu virtual machine (as described in a following section), we only need to allocate the space necessary to install the OS, the software packages we use (Python, IRAF, etc.), plus some room for log and temporary files. 20 or 25 GB should be fine.

Note that in principle disk space and RAM cannot be changed after the virtual machine is created (though there seem to be some not-so-easy ways to achieve disk resizing - see https://github.com/canonical/multipass/issues/62). Feel free to set different disk size and RAM depending on your needs.

Multipass images and related files are stored in directory: /var/root/Library/Application\ Support/multipassd/

List all installed images:
multipass list
(the one just installed will be shown)

Now we use the exec command to launch a bash shell, where we will then update Ubuntu and install the various packages we need:
multipass exec ubuntu2204-25G -- bash --login
The double dash separates the options passed to multipass from the command executed and its own flags. The --login flag is to start a login shell which reads ~/.bash_profile (if there is no such file in the Ubuntu home directory, no problem, we'll create it later on).

We thus get a new prompt indicating we are working in the newly created Ubuntu machine. Note that the default user is named "ubuntu".

Upgrade Ubuntu and install packages

Now we upgrade Ubuntu and install those packages we want in exactly the same way we would do it on an Ubuntu desktop or laptop.
sudo apt update
sudo apt upgrade
(no password required for sudo)

We continue with the installation of specific packages required by IRAF and PyRAF, in particular some 32-bit compatibility libraries
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install git libx11-dev tcsh
sudo apt install lib32gcc-12-dev lib32gcc-11-dev lib32ncurses-dev libxmu6:i386 libxtst6:i386 libtinfo5:i386 libncurses5:i386 libncurses5

Install DS9, from the Ubuntu repository:
sudo apt install saods9

Install python3 packages (the most common ones, and a few required for PyRAF)
sudo apt install python3 python3-pip python3-wheel python3-matplotlib python3-numpy python3-scipy python3-astropy python3-tk python3-ipython python3-pygments python3-jedi

Install (as regular user, that is without sudo) additional packages for PyRAF:
python3 -m pip install --user pmw
python3 -m pip install --user d2to1
python3 -m pip install --user stsci.tools
python3 -m pip install --user pyraf

Download the IRAF installer (which is also valid for more recent Ubuntu releases than the one indicated in the filename)
wget -cNS ftp://siesoft:siesoft@ftp.iac.es/iraf-2.16.1_Ubu1804.run
This may take a while (almost 900 MB to download).

Run the installer:
sudo sh iraf-2.16.1_Ubu1804.run

Define some IRAF-related variables in .bash_profile
echo '# IRAF-related variables' >> ~/.bash_profile
echo 'export iraf="/opt/iraf/iraf-2.16.1/"' >> ~/.bash_profile
echo 'export IRAFARCH="linux64"' >> ~/.bash_profile
(or edit manually ~/.bash_profile to add the above export statements)

Do a simple test, as regular user (no sudo)
source ~/.bash_profile
If a list of IRAF packages is displayed, perhaps with a warning about login.cl not found, then all is good so far.

Enable graphics

First of all, install XQuartz if you haven't already done so.

To enable graphics, first we need to change a few settings in XQuartz. Launch it (it's in the Utility Folder), open the Preferences windows, click on Security, and enable "Allow Connections from Network Clients". In our case, we had to reboot the Mac laptop for XQuartz to pick up this change. Before rebooting, we stopped our Ubuntu virtual machine, typing the following command in a Mac terminal window (not from Ubuntu itself):
multipass stop ubuntu2204-25G
Everything we did is preserved and will be available again when we restart Ubuntu.

After the reboot is complete and we are logged in again, relaunch Ubuntu
multipass start ubuntu2204-25G
multipass list
The latter command will show the status of our Ubuntu machine.

Then we launch a bash shell as done before:
multipass exec ubuntu2204-25G -- bash --login

At this point, we need both the IP of the mac host, and the IP of the virtual machine. The former can be obtained by typing the following command in a Mac terminal window:
export IP_mac=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}') ; echo $IP_mac
The latter can be obtained by running multipass list, where it will be listed in the IPv4 column; let's call it IP_ubu.

Take note of both IP values. They probably change depending on the internet connection used (home own WiFi, "iacint" at the IAC, connected to some other network, etc.)

On the Mac terminal write
xhost + IP_ubu
where IP_ubu is the IP of the Ubuntu machine (something like, for instance, This command must probably be repeated if you log out and log in again, of after resuming a session.

On Ubuntu, write the following command
export DISPLAY="IP_mac:0"
where IP_mac is the IP of the Mac host, for instance: export DISPLAY= (at this time we do not know if this process - IPs determination, setting the DISPLAY variable, and the xhost command - can be automatized)

Try launching xgterm (the graphics terminal used by IRAF)
xgterm -ls -sb
Hopefully, an XGTerm shows up (-ls will run a login shell in the XGTerm, while -sb enables the scrolling bar).

Initialize and use IRAF/PyRAF

First of all, initialize IRAF/PyRAF by creating the login.cl file, which must reside in the iraf subdirectory in your home. Do not run mkiraf in your home directory, or in the directory where you keep your data, or anywhere else.
mkdir ~/iraf
cd ~/iraf/
(Enter xgterm as terminal type when prompted).

Now let display a simple image to check that PyRAF is working correctly.
ds9 &
from pyraf import iraf
iraf.display("dev$pix", 1)
(dev$pix is an example image included in the IRAF distribution)

Share files between macOS and Ubuntu

One of the useful features of Multipass is that it allows mounting a directory of the macOS host so that it's visible from the Ubuntu instance. For instance:
In the Ubuntu shell:
mkdir /home/ubuntu/data_share
In a Mac terminal
multipass mount /Users/your_username/data_share ubuntu2204-25G:/home/ubuntu/data_share

Here we use the name data_share on both Mac and Ubuntu for the directory with the shared data. Replace your_username by your actual username on the Mac. The directory must already exist on the Mac. Feel free to use a different naming scheme.

Again in Ubuntu shell, check that the data are indeed present:
ls -al /home/ubuntu/data_share

To unmount:
multipass umount ubuntu2204-60G

Note that the macOS directory to be mounted must have at least read permissions for other users. For some directories, for instance Downloads and Documents (and possibly others), you may also need to give Full Disk access to Multipass in the System Preferences -> Security & Privacy -> Privacy settings.

In general, you can work on the shared directory from the Mac and from Ubuntu at the same time. For instance I edit a PyRAF script on Mac, run it on the Ubuntu terminal, and display the output figures from the Mac terminal.

If the multipass mount command issues an error message suggesting to install multipass-sshfs, try installing in the Ubuntu instance, the sshfs package: sudo apt install sshfs


Remote display does not work

Make sure that the security settings in XQuartz are correct (see the X11 Preferences figure in https://sudhakaryblog.wordpress.com/2020/12/16/run-linux-x11-apps-in-docker-and-display-on-a-mac-os-x-desktop/). If you just changed them, you may need to reboot the Mac to activate the new settings. Also, try executing command xhost + IP_ubu again.

PyRAF and numpy issues

If when running PyRAF you get an error message like:
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd.
ImportError: numpy.core.multiarray failed to import

try upgrading numpy with command: python3 -m pip install --upgrade --user numpy

Multipass shell does not start, or hangs, or misbehaves

If multipass starts behaving oddly, for instance one cannot stop running instances, or cannot start a new shell, a solution that works for me is to kill the multipass daemon with:
sudo kill $(ps -ef|grep "bin/multipassd" | grep -v grep | awk '{print $2}')
and then restart multipass by double-clicking on the Multipass icon in the Dock.

edit · print · PDF
Page last modified on February 18, 2024, at 11:22 PM