ethereum/go-ethereum · error

environment variable LocalAppData is undefined

Error message

environment variable LocalAppData is undefined

What it means

When computing the default data directory on Windows, geth reads LOCALAPPDATA; the comment states Windows XP lacks it and unsupported environments cause cascading issues, so the code panics if the variable is empty. It is a startup-time environment assertion, not a runtime failure.

Source

Thrown at node/defaults.go:118

			if appdata == "" || common.IsNonEmptyDir(fallback) {
				return fallback
			}
			return filepath.Join(appdata, "Ethereum")
		default:
			return filepath.Join(home, ".ethereum")
		}
	}
	// As we cannot guess a stable location, return empty and handle later
	return ""
}

func windowsAppData() string {
	v := os.Getenv("LOCALAPPDATA")
	if v == "" {
		// Windows XP and below don't have LocalAppData. Crash here because
		// we don't support Windows XP and undefining the variable will cause
		// other issues.
		panic("environment variable LocalAppData is undefined")
	}
	return v
}

func homeDir() string {
	if home := os.Getenv("HOME"); home != "" {
		return home
	}
	if usr, err := user.Current(); err == nil {
		return usr.HomeDir
	}
	return ""
}

View on GitHub (pinned to 6bb0588ad8)

Solutions

  1. Set LOCALAPPDATA for the process/user: 'setx LOCALAPPDATA C:\Users\me\AppData\Local' or set it in the service's environment block.
  2. Bypass default-path computation entirely by passing an explicit --datadir D:\chaindata.
  3. Restore the standard user profile environment (run under a normal user session) before starting the node.

Example fix

# before
geth --syncmode snap

# after
geth --datadir D:\eth-data --syncmode snap
Defensive patterns

Strategy: validation

Validate before calling

func ensureAppDataEnv() error {
    if runtime.GOOS == "windows" && os.Getenv("LOCALAPPDATA") == "" {
        return errors.New("LOCALAPPDATA is unset; set it or pass --datadir explicitly")
    }
    return nil
}
// call at process start, before node.New / defaults

Try / catch

Check the env var (or always pass --datadir) before startup; recovering after the panic leaves no datadir to use.

Prevention

When it happens

Trigger: Running a geth-based binary on Windows where the LOCALAPPDATA environment variable is unset or empty — e.g. minimal service accounts, hardened/sandboxed environments, CI runners with stripped env, or shells started without the standard user profile.

Common situations: Running geth as a Windows service or scheduled task with a restricted environment; containers/WSL misconfigurations invoking Windows binaries; env cleared by orchestration tooling.

Related errors


AI-assisted analysis of ethereum/go-ethereum@6bb0588ad8 (2026-08-15). Data as JSON: /api/errors/2b1254dde1ece183. Report an issue: GitHub.