How to install singularity on a local machine

Singularity is the software tool used by the HPC to manage containers in the cluster. The instructions following are about the version 3.4 which is the current version running on the Lichtenberg cluster. Singularity runs on Linux natively while for Windows or Mac a virtual machine is needed.

Singularity is installed on the Lichtenberg cluster under /usr/bin/singularity. Find out its current version with singularity --version.

Step-by-step guide

Linux

  1. Install dependencies, according to your OS:
    Ubuntu or Arch

    # Choose either A or B, depending on your OS
    # A) Dependencies for Ubuntu
    sudo apt-get update && sudo apt-get install -y \
        build-essential \
        libssl-dev \
        uuid-dev \
        libgpgme-dev \
        squashfs-tools \
        libseccomp-dev \
        wget \
        pkg-config \
        git \
        cryptsetup-bin
    
    # B) Dependencies for Arch Linux
    pacman -Syyu --noconfirm make gcc gpg-crypter squashfs-tools libseccomp wget pkg-config git sudo
    
  2. Install Go:

    export VERSION=1.14 OS=linux ARCH=amd64                       && \
        wget https://dl.google.com/go/go$VERSION.$OS-$ARCH.tar.gz && \
        sudo tar -C /usr/local -xzvf go$VERSION.$OS-$ARCH.tar.gz  && \
        rm go$VERSION.$OS-$ARCH.tar.gz
    
    # Set up environment for Go
    echo 'export GOPATH=${HOME}/go' >> ~/.bashrc                                && \
        echo 'export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin' >> ~/.bashrc && \
        source ~/.bashrc
    
  3. Download Singularity source code & compile
    (It is advised to check the version running on the cluster and download/checkout the same version):

    # Choose either A or B
    # A) Get a specific release of Singularity
    export VERSION=3.5.3 && # adjust this as necessary \
        wget https://github.com/sylabs/singularity/releases/download/v${VERSION}/singularity-${VERSION}.tar.gz && \
        tar -xzf singularity-${VERSION}.tar.gz && \
        cd singularity
    
    # B) Get the latest source code. Careful this might break things
    git clone https://github.com/sylabs/singularity.git && \
        cd singularity && \
        git checkout master
    
    # Compile Singularity
    ./mconfig              && \
        make -C ./builddir && \
        sudo make -C ./builddir install
    

    CentOS and Debian/Ubuntu have already build packages which can be installed using yum and apt respectively and require none of the above steps.

Options

By default Singularity will be installed in the /usr/local directory. To specify a different path use the --prefix option in step 3 above while compiling:

./mconfig --prefix=/opt/singularity &&\
    make -C ./builddir &&\
    sudo make -C ./builddir install

See also