Install Spack on Ubuntu 20.04

Updated on January 22, 2021
Install Spack on Ubuntu 20.04 header image

Introduction

Spack is a package manager to install scientific packages such as The Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST) or PNGwriter. This guide explains how to install Spack on an Ubuntu 20.04 Vultr cloud instance.

Prerequisites

1. Install Dependencies

Install the build-essential.

$ sudo apt install build-essential

2. Clone Spack Repository

Clone the Spack repository to ~/.spack/Spack, or a directory of your choice.

$ git clone https://github.com/spack/spack ~/.spack/Spack

3. Add Shell Support

To use Spack everywhere, add Spack to PATH:

$ . ~/.spack/Spack/share/spack/setup-env.sh

To use the spack command every login, append that command to ~/.bash_profile:

$ echo '. ~/.spack/Spack/share/spack/setup-env.sh' >> ~/.bash_profile

Then run source ~/.bash_profile or log out to make changes take effect.

4. Clear Environment

Because Spack builds and installs packages from their source code, it requires a clean environment. Make sure your PATH only has the things you need.

$ echo $PATH
/home/cus/.spack/Spack/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

5. Test Spack

Verify the Spack installation.

$ spack -V
0.16.0-359-860825ee1

Next Steps

You can install lots of powerful scientific packages via Spack, such as pngwriter.

$ spack install pngwriter
$ spack load pngwriter

More Resources