Golang在Debian打包失败可按以下步骤排查解决:
检查基础环境
go version
sudo apt update
sudo apt install build-essential libbpf-dev linux-headers-$(uname -r)
处理依赖问题
go.mod文件正确:go mod init <module-name> # 初始化
go mod tidy # 清理/添加依赖
export GOPROXY=https://mirrors.tuna.tsinghua.edu.cn,direct
排查代码与编译错误
go build -x查看详细编译过程,定位错误环节。os等基础包,并检查内核版本兼容性。优化编译配置
go clean -cache
go build
-ldflags="-s -w"参数减少依赖。查看日志与社区支持
关键命令总结:
go mod init/tidy/getgo build -x -ldflags="-s -w"go version、uname -r