快速定位与修复清单
常见报错与对应修复
“go: Command not found”
原因:构建环境缺少 golang-go。
修复:在构建机执行 sudo apt-get update && sudo apt-get install golang-go,确认 go version 正常;再运行 debuild -us -uc。若你曾手动设置 GOROOT/GOPATH,请保证构建环境也能访问或在 rules 中显式设置。
“dh_auto_configure/dh_auto_build: go: not found”
原因:debian/control 未声明 Build-Depends: golang-go, dh-golang,导致构建环境没有 Go 或 dh-golang。
修复:在 debian/control 正确声明构建依赖,确保 dh-golang 参与构建流程。
“cannot find package … in /usr/share/gocode/src/…/xxx”
原因:上游依赖尚未被打包进 Debian,或 dh-golang 未能在构建环境中找到对应 golang-
修复:为缺失依赖创建或安装相应的 golang-
“binary-without-manpage / hardening-no-relro” 等 lintian 警告
原因:Go 常为静态二进制,部分传统检查不适用。
修复:优先补齐缺失内容(如添加手册页);对确实不适用的规则,使用 debian/lintian-overrides/
“debuild 失败但 dpkg-buildpackage 成功”
原因:debuild 默认会运行 lintian,而 dpkg-buildpackage -b 只做构建。
修复:本地调试可用 dpkg-buildpackage -us -uc -b;提交或发布前再恢复 debuild 并通过合适的 lintian overrides 处理少数不适用的警告。
最小可用的 debian/ 配置示例
Source: my-go-app
Section: utils
Priority: optional
Maintainer: Your Name <you@example.com>
Build-Depends: debhelper-compat (= 13), dh-golang, golang-go
Standards-Version: 4.6.0
Homepage: https://github.com/your/my-go-app
Vcs-Git: https://github.com/your/my-go-app.git
Vcs-Browser: https://github.com/your/my-go-app
Package: my-go-app
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: A brief description of my Go application.
A longer description here.
#!/usr/bin/make -f
export GOPATH := $(CURDIR)/.gopath
export GOBIN := $(CURDIR)/bin
%:
dh $@ --with golang
override_dh_auto_install:
dh_golang_install
# 如有额外资源:dh_install path/to/config.toml /etc/my-go-app/
override_dh_auto_clean:
dh_auto_clean
rm -rf $(GOPATH) $(GOBIN)
debuild -us -uc
lintian ../my-go-app_*.changes
以上示例遵循 dh-golang 推荐做法,简洁且符合 Debian 规范。
进阶与替代方案