Installing Packages
-
Installing a package with Spack is very simple. To install a package, you simply type:
spack install <packaage_name>
-
For example, to install
zlib
software, you simply type:spack install zilb
For more details on installing packages, please visit Spack Documentation.
Specifying Compilers
-
In Spack, you can request specific configurations of the package. For example, you can specify compilers using
%
symbol. For example, to installzlib
package usinggcc
compiler, you type:spack install zilb %gcc
Specifying Versions of Compilers and Packages
-
Each package may have different versions. Spack allows users to specify which version of a package to install.
-
You can check for particular versions before requesting them. To show all available versions of a specific software, you type:
spack versions <package_name>
-
For example, to list versions of
zlib
, you simply type:spack versions zlib
-
This will print all available versions of
zlib
as follows:==> Safe versions (already checksummed): 1.2.11 1.2.8 1.2.3 ==> Remote versions (not yet checksummed): 1.2.10 1.2.6 1.2.4.3 1.2.3.6 1.2.2.3 1.2.0.8 1.2.0.1 1.0.9 1.0.1 0.91 1.2.9 1.2.5.3 1.2.4.2 1.2.3.5 1.2.2.2 1.2.0.7 1.2.0 1.0.8 1.0-pre 0.79 ...
-
The output has two sections:
-
Safe versions (already checksummed): the versions that Spack knows about. In other words, the versions that were added to the package.
-
Remote versions: the versions that are available on the remote server that weren’t added to the Spack package.
-
-
The
@
symbol is used to specify versions of packages and compilers. To install the version1.2.11
ofzlib
, you type:spack install zlib@1.2.11
-
If you want to use the version
4.8.5
of thegcc
compiler when installing the version1.2.11
ofzlib
, you type:spack install zlib@1.2.11 %gcc@4.8.5
If you don’t specify the version of a package, Spack will install the default version of that package.
Specifying Compiler Flags
-
Spack allows users to include compiler flags in the command line when installing a package. Spack accepts
cppflags, cflags, cxxflags, fflags, ldflags
, andldlibs
flags. The values of these flags must be quoted if they included spaces. These values are injected into the compile line automatically by the Spack compiler wrappers. -
For example, to install an optimized version of zlib, you need to use
-O3
flag. This can be accomplished by specifying the value ofcppflags
in the command line as follows:spack install zlib cppflags=-O3
Specifying Dependencies
-
Some packages may depend on other packages. This means that when a package is installed, all its dependencies are installed. Dependencies can be explicitly requested using the
^
symbol. Anything you could specify about the top-level package, you can also, specify about dependencies using^
. -
For example, the
tcl
package depends on thezlib
package. Suppose you want to use a specific version ofzlib
as a dependency, you can specify that in the command line as follows:spack install tcl ^zlib@1.2.8
-
This command installs the default version of
tcl
and its dependencyzlib
at the version1.2.8
.
Changing Build Options
-
Spack packages can also have build options, called variants. Some variants may be boolean where they can be
True
orFalse
. They can be specified using the+
forTrue
and~
or-
forFalse
. Variants (boolean or otherwise) can also be specified using the same syntax as compiler flags. -
For example, the default version of the
HDF5
package is installed withMPI
support. Suppose you want to install its serial version, you need to disable theMPI
support. This can be accomplished by making thempi
variantFalse
as follows:spack install hdf5~mpi
-
There are other packages that provide the
MPI
interface such asopenmpi, mpich,
andmvapich
. You might want to install a package with a differentMPI
implementation. Spack handles these throughvirtual dependencies
. For instance,HDF5
can depend on theMPI
interface. -
If you would like to change the
MPI
support ofHDF5
toopenmi
, you type:spack install hdf5+mpi ^openmpi
Reusing Installed Dependencies
-
By default, when you try to install a package using
spack install
, Spack tries to build that package along with its dependencies. If one of the dependencies is already installed with a different version that’s specified in thespec
of the package, Spack won’t use the installed dependency. Instead, it builds the dependency with the appropriate version. This means that the dependency will be built twice. Spack allows you to try hard to reuse existing installations as dependencies by adding the--reuse
option to thespack install
command. -
For example, the
nano
package depends on thencurses@6.2
package. Suppose you have installedncurses@6.1
before, and you want to installnano
as follows:spack install nano
-
Spack will install
ncurses@6.2
and all other dependencies ofnano
, and then it will install the package. This means that two versions ofncurses
are installed. -
Instead of installing
ncurses@6.2
as a dependency, you can force Spack to use the already installed version ofncurses (ncurses@6.1)
. To do so you type:spack install --reuse nano
-
Spack tries to find if any of the dependencies of
nano
with the same or different version is already installed. In this example, Spack findsncurses@6.1
already built. Therefore, it won’t installncurses@6.2
. It has reusedncurses@6.1