Uninstalling Packages

You can uninstall packages using spack uninstall command. There are different cases you may face while uninstalling packages. For example, you may have different configurations of the same version of a package. The following sub-sections will explore those forms and show how to uninstall packages in each form. To get more details you can refer to Spack Documentation.

One Spec of a Package

If you’ve installed a package using only one spec, then you can simply uninstall that package as follows:

spack uninstall [options] <package_name>

The following table shows the most common options that can be used with the spack uninstall command.

Flag Description

-f

remove regardless of whether other packages or environments depend on this one

-R

uninstall any packages that depend on the ones given via command line

-a

remove all installed packages that match each supplied spec

For example, if you show the currently installed packages using spack find command you get the following output:

==> 63 installed packages
-- linux-centos7-x86_64 / gcc@4.8.5 -----------------------------
autoconf@2.69        gdbm@1.18.1      libtool@2.4.6  perl@5.32.0    zlib@1.2.11
automake@1.16.2      gmp@6.1.2        m4@1.4.18      pkgconf@1.7.3
berkeley-db@18.1.40  isl@0.20         mpc@1.1.0      readline@8.0
diffutils@3.7        libiconv@1.16    mpfr@3.1.6     tcl@8.6.10
...

The output shows that the tcl package was installed once with only one spec. In this case, you can uninstall it by simply typing:

spack uninstall tcl

Sometimes when you try to uninstall a package that’s dependent on other packages, you get an error that prevents you from uninstalling the package. For example, the tcl package depends on the zlib package. If you try to uninstall zlib, you get the following error:

==> Will not uninstall zlib@1.2.11%gcc@4.8.5/64vg6e4
The following packages depend on it:
    -- linux-centos7-x86_64 / gcc@4.8.5 -----------------------------
    vxq35mm gcc@9.3.0  3vbkxar tcl@8.6.10

==> Error: There are still dependents.
  use `spack uninstall --dependents` to remove dependents too

If you would like to uninstall zlib regardless of whether other packages or environments depend on it, you type:

spack uninstall -f zlib

zlib will be uninstalled even if there are some other packages depend on it.

If you would like to uninstall zlib and its dependents, you type:

spack uninstall -R zlib

This command removes zlib and all packages depend on it (gcc@9.3.0 and tcl@8.6.10).

You can uninstall a package that was installed using different specs. For example, zlib has been installed using different specs. To show the installed versions of zlib, type:

spack find zlib

The following output shows that 5 versions of zlib have been installed. If you try to uninstall zlib using its name you get an error.

spack uninstall zlib

Output:

==> Error: zlib matches multiple packages:

    -- linux-centos7-x86_64 / gcc@4.8.5 -----------------------------
    ss3zkvn zlib@1.2.8  64vg6e4 zlib@1.2.11

    -- linux-centos7-x86_64 / gcc@9.3.0 -----------------------------
    7hnjrwi zlib@1.2.8  o5eyrr4 zlib@1.2.11  oodul3l zlib@1.2.11

==> Error: You can either:
    a) use a more specific spec, or
    b) specify the spec by its hash (e.g. `spack uninstall /hash`), or
    c) use `spack uninstall --all` to uninstall ALL matching specs.

If you want to uninstall all installed versions of zlib, you can use the -a option as follows:

spack uninstall -a zlib

If you would like to uninstall a specific version of the installed versions of zlib, you can do so by using the hash of that version. This will be shown that in the following sections.

Different Versions with Different Specs

Suppose you have installed a package with different versions where each version was installed using a different spec. For instance, you can show the installed version of tcl as follows:

spack find tcl

Output:

==> 2 installed packages
-- linux-centos7-x86_64 / gcc@4.8.5 -----------------------------
tcl@8.6.10

-- linux-centos7-x86_64 / gcc@9.3.0 -----------------------------
tcl@8.5.19

The output shows that two versions of tcl have been installed (tcl@8.6.10 and tcl@8.5.19). You won’t be able to uninstall any of them using the package_name.

spack uninstall tcl

Output:

==> Error: tcl matches multiple packages:

    -- linux-centos7-x86_64 / gcc@4.8.5 -----------------------------
    3vbkxar tcl@8.6.10

    -- linux-centos7-x86_64 / gcc@9.3.0 -----------------------------
    7qka2cb tcl@8.5.19

==> Error: You can either:
    a) use a more specific spec, or
    b) specify the spec by its hash (e.g. `spack uninstall /hash`), or
    c) use `spack uninstall --all` to uninstall ALL matching specs.

In this case, you can use the hashes of the installed packages. To show the hashes of tcl, type:

spack find -l tcl

The following output shows that two versions of tcl have been installed along with their hashes.

==> 2 installed packages
-- linux-centos7-x86_64 / gcc@4.8.5 -----------------------------
3vbkxar tcl@8.6.10

-- linux-centos7-x86_64 / gcc@9.3.0 -----------------------------
7qka2cb tcl@8.5.19

You can uninstall any of the installed packages using its hash. To uninstall tcl@8.5.19, you can use its hash 7qka2cb as follows:

spack uninstall /7qka2cb

You will be asked if you want to proceed. You type Y and the package will be uninstalled.

==> The following packages will be uninstalled:

    -- linux-centos7-x86_64 / gcc@9.3.0 -----------------------------
    7qka2cb tcl@8.5.19

==> Do you want to proceed? [y/N] y
==> Successfully uninstalled tcl@8.5.19%gcc@9.3.0 arch=linux-centos7-x86_64/7qka2cb
It’s recommended to using the hash to uninstall packages to avoid any confusion.