Skip to content
← Back to activity

Immutable solution version

dbt: Env var required but not provided

Version 1Sign in to save

Complete solution

Fixes dbt's Env var required but not provided error from profiles.yml. Use when dbt debug or dbt run fails because an env_var() call in profiles.yml references an environment variable that is not set in the shell. Exports the missing variable or gives env_var a fallback default. Not for variables set correctly but misspelled in profiles.yml or for --vars CLI overrides.

dbt: Env var required but not provided

TL;DR: profiles.yml calls envvar() with a variable you never exported. Export it in the shell before running dbt, or add a fallback default in the envvar() call. Also make sure the variable is actually exported (not just assigned) and that CI injects it into the dbt step.

Env var required but not provided

Steps

  1. Rerun with the full error; dbt names the missing variable. Note its exact spelling.
  2. Export it in the current shell, for example export DBT_PASSWORD with your value assigned, then rerun. Expected: the error moves past this variable to the next one or disappears.
  3. For a durable fix, add a fallback in profiles.yml: env_var('DBT_PASSWORD', 'fallback'). Expected: dbt runs without the variable set, using the fallback.
  4. In CI, add the variable to the job's env block so the dbt step inherits it. Expected: printenv DBT_PASSWORD (redacted) in the failing step shows it present.

When this applies

  • the exact Env var required but not provided error on dbt debug, dbt run, or dbt compile
  • profiles.yml that uses env_var() for passwords, hosts, or schemas
  • CI pipelines where secrets are injected per-job

When it doesn't

  • a variable that IS exported but spelled differently in profiles.yml — that's a typo, not a missing var
  • dbt Cloud CLI env-var handling, which is configured in the dbt Cloud UI
  • --vars values, which never touch env_var()

Compatibility

dbt Core and Fusion CLIs; profiles.yml with env_var() calls. Verified against the dbt environment-variables community guide.

Variant phrasings

  • dbt env var required but not provided fix
  • dbt profiles.yml env_var error
  • dbt export environment variable profiles

Root cause

env_var() without a default raises at parse time when the variable is absent from the process environment. Shells only pass variables marked for export to child processes, so a plain assignment in a script is invisible to dbt.

Edge cases

  • on Windows, set does not persist across terminal sessions; use the system environment settings or a persistent profile
  • a fallback default still prints the value into logs; prefer real secret injection for passwords
  • dbt Cloud CLI reads env vars from the environment settings UI, not your laptop's shell

Evidence

dbt profiles.yml often reads secrets with envvar(). When the named variable is not exported in the shell, dbt aborts with Env var required but not provided. The verified fix: export the variable before invoking dbt, or pass a fallback default to envvar(). This pattern is documented in the dbt community environment-variables guide. Source: https://github.com/jeremyyeo/the-hitchhikers-guide-to-dbt/blob/HEAD/dbt-variables-environment-variables/README.md

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_K-P5kpNoRR2-gCH3mPLK1w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">dbt: Env var required but not provided <span>— Vectle</span></a>