flipped-aurora/gin-vue-admin · error

服务器未安装 Go 工具链,无法编译: %w

Error message

服务器未安装 Go 工具链,无法编译: %w

What it means

compileCliBinary shells out to the Go toolchain to cross-compile the CLI binary. Before doing anything it runs exec.LookPath("go"); when the `go` executable is not found in the server's PATH, this error is returned wrapping the underlying exec error. The service cannot build without a Go toolchain installed on the host.

Source

Thrown at server/plugin/ai/service/sys_cli_build.go:82

	if err != nil {
		return "", nil, err
	}
	manifest, err := buildSysCliManifest(cli, bindings)
	if err != nil {
		return "", nil, err
	}
	applyCliBuildBaseURL(&manifest, req.BaseURL)
	manifestBytes, err := marshalSysCliManifest(manifest)
	if err != nil {
		return "", nil, err
	}
	return s.compileCliBinary(cli, manifestBytes, goos, goarch)
}

// compileCliBinary 把 manifest 内嵌进 gva 源码副本并交叉编译,返回二进制文件名与内容。
func (s *cliService) compileCliBinary(cli autoModel.SysCli, manifestBytes []byte, goos, goarch string) (string, []byte, error) {
	if _, err := exec.LookPath("go"); err != nil {
		return "", nil, fmt.Errorf("服务器未安装 Go 工具链,无法编译: %w", err)
	}
	absBuildRoot, err := filepath.Abs(cliBuildDir)
	if err != nil {
		return "", nil, fmt.Errorf("解析编译目录失败: %w", err)
	}
	if err := os.MkdirAll(absBuildRoot, 0o755); err != nil {
		return "", nil, fmt.Errorf("创建编译根目录失败: %w", err)
	}

	buildDir, err := os.MkdirTemp(absBuildRoot, "cli-")
	if err != nil {
		return "", nil, fmt.Errorf("创建编译目录失败: %w", err)
	}
	defer os.RemoveAll(buildDir)

	if err := copyCliSources(cliSourceDir, buildDir); err != nil {
		return "", nil, err
	}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Install the Go toolchain on the server (e.g. download from go.dev/dl and extract to /usr/local/go)
  2. Add Go to the server process PATH, e.g. set PATH=/usr/local/go/bin:$PATH in the systemd unit or container env
  3. If using Docker, base the runtime image on golang:<ver> or install Go in the runtime stage
  4. Verify with `sudo -u <server-user> which go` that the exact service user can find go
  5. Precompile binaries offline and expose a download endpoint instead of compiling at runtime

Example fix

// before (dockerfile runtime stage)
FROM alpine:3.19
// after
FROM golang:1.22-alpine
# or: RUN apk add --no-cache go && export PATH=$PATH:/usr/lib/go/bin
Defensive patterns

Strategy: validation

Validate before calling

if _, err := exec.LookPath("go"); err != nil {
    return errors.New("Go toolchain required for CLI builds is not installed on the server")
}

Try / catch

bin, content, err := svc.BuildCliBinary(cli, manifest, goos, goarch)
if err != nil {
    if strings.Contains(err.Error(), "未安装 Go 工具链") {
        return nil, errors.New("server missing Go toolchain; install Go or use prebuilt binaries")
    }
    return err
}

Prevention

When it happens

Trigger: Invoking BuildCliBinary or BuildCliSkill on a server where the go binary is not installed, not in PATH for the server process user, or the service runs in a slim Docker image without the Go toolchain.

Common situations: Deploying in distroless/alpine runtime images that only contain the compiled binary; systemd services with a restricted PATH missing /usr/local/go/bin; container images built with multi-stage builds where Go was only in the builder stage; running under a user whose PATH differs from the shell's.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/6eca38120daf5f40. Report an issue: GitHub.