direnv/direnv · error
current version %s is older than the desired version %s
Error message
current version %s is older than the desired version %s
What it means
direnv's `version` command compares the running binary's version (semVersion) against a user-supplied semver argument. When the current version is older than the desired version (semver.Compare returns < 0), the command fails with this error so callers (e.g. scripts pinning a minimum direnv version) can detect an outdated binary.
Source
Thrown at internal/cmd/cmd_version.go:25
"golang.org/x/mod/semver"
)
// CmdVersion is `direnv version`
var CmdVersion = &Cmd{
Name: "version",
Desc: "prints the version or checks that direnv is older than VERSION_AT_LEAST.",
Args: []string{"[VERSION_AT_LEAST]"},
Aliases: []string{"--version"},
Action: actionSimple(func(_ Env, args []string) error {
semVersion := ensureVPrefixed(version)
if len(args) > 1 {
atLeast := ensureVPrefixed(args[1])
if !semver.IsValid(atLeast) {
return fmt.Errorf("%s is not a valid semver version", atLeast)
}
cmp := semver.Compare(semVersion, atLeast)
if cmp < 0 {
return fmt.Errorf("current version %s is older than the desired version %s", semVersion, atLeast)
}
} else {
fmt.Println(version)
}
return nil
}),
}
func ensureVPrefixed(version string) string {
if !strings.HasPrefix(version, "v") {
return "v" + version
}
return version
}
View on GitHub (pinned to b00e451f54)
Solutions
- Upgrade direnv to a version >= the requested one (e.g. `go install github.com/direnv/direnv/v2@latest` or update the system package).
- Lower the requested version argument to one the installed binary satisfies if the newer features are not actually needed.
- If the check runs in CI, install a pinned direnv version in the job setup before invoking `direnv version`.
- Handle the non-zero exit gracefully in scripts and print upgrade instructions.
Example fix
// before (fails on old binary) direnv version 2.32.0 // after # install an up-to-date binary first go install github.com/direnv/direnv/v2@latest direnv version 2.32.0
Defensive patterns
Strategy: validation
Validate before calling
ver=$(direnv version 2>/dev/null || echo v0.0.0) want=v2.32.0 if [ "$(printf '%s\n%s\n' "$ver" "$want" | sort -V | head -n1)" != "$want" ]; then echo "direnv $ver is older than required $want" >&2; exit 1 fi
Try / catch
if ! out=$(direnv version "$want" 2>&1); then echo "$out" >&2 # current version ... is older than ... echo "upgrade direnv (e.g. go install github.com/direnv/direnv/v2@latest)" >&2 fi
Prevention
- Pin and install a minimum direnv version in CI/provisioning before running version checks.
- Use sort -V or a semver tool to pre-check versions in shell scripts.
- Keep direnv updated via your package manager or go install @latest.
- Fail fast with a clear upgrade message when the check fails.
When it happens
Trigger: Running `direnv version <x.y.z>` where the argument passes semver.IsValid but semver.Compare(current, atLeast) < 0 — i.e. the installed direnv is strictly older than the requested version. The argument must already be V-prefixed (ensureVPrefixed) and valid semver, otherwise a different error fires.
Common situations: CI scripts or provisioning tools assert a minimum direnv feature set; the installed binary (from an old package manager snapshot or system package) predates the required release. Common after OS upgrades or when using distro-packaged direnv that lags upstream.
Related errors
- %s is not a valid semver version
- missing PATH argument
- invalid arguments
- too many arguments
- a shell name is required
AI-assisted analysis of direnv/direnv@b00e451f54 (2026-09-05).
Data as JSON: /api/errors/9ee01ae45a324a7f.
Report an issue: GitHub.