cloudflare/cloudflared · error

error determining install path

Error message

error determining install path

What it means

Wrapped by uninstallLaunchd when it fails to compute the installed plist path (needed to rebuild the template and resolve its location before removing the service). installPath() uses resolveLibraryPath, so this is almost always the homedir.Dir() failure to find the user's home directory, meaning cloudflared cannot tell which plist file to uninstall.

Source

Thrown at cmd/cloudflared/macos_service.go:232

	log.Info().Msgf("Outputs are logged to %s and %s", stderrPath, stdoutPath)
	err = runCommand("launchctl", "load", plistPath)
	if err == nil {
		log.Info().Msg("MacOS service for cloudflared installed successfully")
	}
	return err
}

func uninstallLaunchd(c *cli.Context) error {
	log := logger.CreateLoggerFromContext(c, logger.EnableTerminalLog)

	if isRootUser() {
		log.Info().Msg("Uninstalling cloudflared as a system launch daemon")
	} else {
		log.Info().Msg("Uninstalling cloudflared as a user launch agent")
	}
	installPath, err := installPath()
	if err != nil {
		return errors.Wrap(err, "error determining install path")
	}
	stdoutPath, err := stdoutPath()
	if err != nil {
		return errors.Wrap(err, "error determining stdout path")
	}
	stderrPath, err := stderrPath()
	if err != nil {
		return errors.Wrap(err, "error determining stderr path")
	}
	launchdTemplate := newLaunchdTemplate(installPath, stdoutPath, stderrPath)
	plistPath, err := launchdTemplate.ResolvePath()
	if err != nil {
		log.Err(err).Msg("error resolving launchd template path")
		return err
	}
	err = runCommand("launchctl", "unload", plistPath)
	if err != nil {
		log.Err(err).Msg("error unloading launchd")

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Run the uninstall with a valid HOME, e.g. `sudo -H cloudflared service uninstall`.
  2. Run as the same user who installed (or as root, which targets /Library/LaunchDaemons).
  3. Fix the user's home directory entry via Directory Services.
  4. Manually remove the plist as a last resort: `sudo launchctl bootout system/com.cloudflare.cloudflared; sudo rm /Library/LaunchDaemons/com.cloudflare.cloudflared.plist`.
Defensive patterns

Strategy: validation

Validate before calling

[ -n "${HOME:-}" ] && [ -d "$HOME" ] || { echo "HOME required for user-level uninstall"; exit 1; }

Try / catch

if err != nil && strings.Contains(err.Error(), "determining install path") { tryManualPlistRemoval() }

Prevention

When it happens

Trigger: `cloudflared service uninstall` on macOS when installPath() -> homedir.Dir() errors: $HOME unset/wrong under sudo, no home directory for the user, OS lookup failure.

Common situations: Uninstalling from a script that scrubbed the environment; running as a different user than the one who installed; corrupted user records after account migration.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/720622b4de230478. Report an issue: GitHub.