Skip to content
Latchkey

just: Load .env Files with set dotenv-load

just can load a .env file into recipe environments when set dotenv-load is turned on.

Many projects keep local configuration in a .env file. just reads it in when you opt in, so recipes see the same variables your app does.

What it does

With "set dotenv-load" at the top of the justfile, just loads key=value pairs from a .env file in the working directory into the environment of every recipe. set dotenv-filename picks a different file name and set dotenv-path picks a different location. Loaded values are available as environment variables, not as just variables, so reference them as $VAR in recipe lines.

Common usage

justfile
# justfile
set dotenv-load

# .env (loaded automatically)
#   DATABASE_URL=postgres://localhost/app
#   APP_ENV=local

migrate:
    echo "using $DATABASE_URL in $APP_ENV"
    ./migrate.sh

# custom file name
set dotenv-filename := ".env.ci"

Syntax

SettingWhat it does
set dotenv-loadLoad a .env file into recipe environments
set dotenv-filename := ".env.ci"Use a different file name
set dotenv-path := "config/.env"Use a different file path
set dotenv-requiredFail if the dotenv file is missing
$VARReference a loaded value in a recipe (it is an env var)

In CI

By default a missing .env is not an error, which lets the same justfile run on a runner that injects secrets through real environment variables instead of a file. Set dotenv-required when the file must exist, or commit a .env.ci and select it with dotenv-filename.

Common errors in CI

Recipes seeing empty $VAR usually means set dotenv-load was omitted, or the values are referenced as {{VAR}} (just-variable syntax) instead of $VAR (environment syntax). With set dotenv-required, a missing file fails with "error: Dotenv file not found". Malformed lines without an = are ignored, which silently drops a value.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →