golang/go · error

%s: argument must be a package path, not an absolute path

Error message

%s: argument must be a package path, not an absolute path

What it means

Returned by PackagesAndErrorsOutsideModule (line 3407) when, after stripping @version, filepath.IsAbs(p) is true. Absolute filesystem paths are rejected for the same reason relative paths are (897): `go install pkg@version` targets a module by import path, not a file on disk. The arg as written is echoed.

Source

Thrown at src/cmd/go/internal/load/pkg.go:3407

		if i := strings.Index(arg, "@"); i >= 0 {
			firstPath, version = arg[:i], arg[i+1:]
			if version == "" {
				return nil, fmt.Errorf("%s: version must not be empty", arg)
			}
			break
		}
	}
	patterns := make([]string, len(args))
	for i, arg := range args {
		p, found := strings.CutSuffix(arg, "@"+version)
		if !found {
			return nil, fmt.Errorf("%s: all arguments must refer to packages in the same module at the same version (@%s)", arg, version)
		}
		switch {
		case build.IsLocalImport(p):
			return nil, fmt.Errorf("%s: argument must be a package path, not a relative path", arg)
		case filepath.IsAbs(p):
			return nil, fmt.Errorf("%s: argument must be a package path, not an absolute path", arg)
		case search.IsMetaPackage(p):
			return nil, fmt.Errorf("%s: argument must be a package path, not a meta-package", arg)
		case pathpkg.Clean(p) != p:
			return nil, fmt.Errorf("%s: argument must be a clean package path", arg)
		case !strings.Contains(p, "...") && search.IsStandardImportPath(p) && modindex.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, p):
			return nil, fmt.Errorf("%s: argument must not be a package in the standard library", arg)
		default:
			patterns[i] = p
		}
	}
	patterns = search.CleanPatterns(patterns)

	// Query the module providing the first argument, load its go.mod file, and
	// check that it doesn't contain directives that would cause it to be
	// interpreted differently if it were the main module.
	//
	// If multiple modules match the first argument, accept the longest match
	// (first result). It's possible this module won't provide packages named by

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Use the module's import path with @version: `go install example.com/app/cmd/app@v1.0.0`.
  2. If you mean to install a local package, drop @version and use a relative path: `go install ./cmd/app`.

Example fix

# before
go install /home/me/app/cmd/app@v1.0.0
# after
go install example.com/app/cmd/app@v1.0.0
Defensive patterns

Strategy: validation

Validate before calling

// Reject absolute paths in `go install pkg@version` args.
package argcheck

import (
	"errors"
	"path/filepath"
	"strings"
)

func NotAbsolutePath(arg string) error {
	p := arg
	if i := strings.Index(arg, "@"); i >= 0 {
		p = arg[:i]
	}
	if filepath.IsAbs(p) {
		return errors.New("absolute path not allowed with @version: " + arg)
	}
	return nil
}

Prevention

When it happens

Trigger: Running `go install /home/me/go/src/app/cmd/app@v1.0.0` or any absolute path with an @version. Common when porting a GOPATH-era script that used absolute paths.

Common situations: Migrating from old GOPATH workflows; CI scripts computing absolute paths; sharing a command line across machines with hardcoded paths.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/987bbdf8db0417be. Report an issue: GitHub.