Skip to content

Environment variables

When a Hermit environment is active, environment variables will be set by Hermit itself, the command-line, the active environment, and installed packages, in that order.


Hermit prefixes all of its own variables with HERMIT_ or _HERMIT_. While it uses a bunch of variables internally, two you can rely on to always be present in an active environment are:

Name Description
HERMIT_ENV Path to the active Hermit environment.
HERMIT_BIN Path to the active Hermit environment bin directory.

An empty environment might look something like the following:

projectšŸš~/project$ hermit env


Use the flag --env=NAME=value to set per-invocation environment variables.

Active Environment

The active environment may define additional environment variables in bin/hermit.hcl. These can be managed with the hermit env command, or by directly editing the configuration file.

For example, to set GOBIN to a build directory within the environment:

projectšŸš~/project$ hermit env GOBIN '${HERMIT_ENV}/build'
projectšŸš~/project$ hermit env       
projectšŸš~/project$ echo $GOBIN

The bin/hermit.hcl file will contain:

# Extra environment variables.
env = {
  "GOBIN": "${HERMIT_ENV}/build",

Use the hermit env command to view and set per-environment variables:

Usage: hermit env [<name>] [<value>]

Manage environment variables.

Without arguments the "env" command will display environment variables for the
active Hermit environment.

Passing "<name>" will print the value for that environment variable.

Passing "<name> <value>" will set the value for an environment variable in the
active Hermit environment."

  [<name>]     Name of the environment variable.
  [<value>]    Value to set the variable to.

  -r, --raw           Output raw values without shell quoting.
      --activate      Prints the commands needed to set the environment to the
                      activated state
      --deactivate    Prints the commands needed to reset the environment to the
                      deactivated state
  -i, --inherit       Inherit variables from parent environment.
  -n, --names         Show only names.
  -u, --unset         Unset the specified environment variable.


Take care to only use single quotes (') when setting values so that the shell doesn’t interpolate environment variables before Hermit. ie. Do not do this:

  projectšŸš~/project$ hermit env GOBIN "${HERMIT_ENV}/build"

as it will result in this bin/hermit.hcl:

# Extra environment variables.
env = {
  "GOBIN": "/home/user/project/build",

This will of course work fine for the local user, but will fail tragically for anyone else.

Installed Packages

Packages may export environment variables for convenience or in order to operate correctly. For example, the go package sets the GOROOT to the location of the installed Go SDK:

projectšŸš~/project$ hermit install go
projectšŸš~/project$ hermit env