Golang项目如何打包以进行部署?

huangapple go评论73阅读模式
英文:

How are golang projects packaged for deployment?

问题

作为一个来自JVM背景的人,我想知道如何将一个golang项目部署到生产环境中。是否有类似于JAR文件的东西?

是否有一个独立的包管理器可以安装在服务器上,并且有一个依赖清单文件,可以在服务器上运行以下载所有依赖项。我特别不想在服务器上构建项目,因为我们不能在生产环境中安装任何编译器等工具。

谢谢。

英文:

Coming from a JVM background I would like to know how to deploy a golang project to production. Is there an equivalent of a JAR file?

Is there a standalone package manager that can be installed on server and a dependency manifest file which can be run to bring down all dependencies on the server. I specifically do not want to have to build the project on the server as we can't have any compilers etc on production boxes.

thanks.

答案1

得分: 8

如果你运行go install <pkg>,二进制文件将被放置在$GOPATH/bin目录下。你可以将该二进制文件复制到另一台具有相同操作系统和架构的机器上。

你也可以进入包含main包的目录,然后直接运行go build。二进制文件将被放置在当前目录下。

Go二进制文件中没有依赖项需要跟踪,它是静态链接的。(一些系统库可能是动态链接的,但如果你在相同的操作系统上运行,这不应该是个问题。)

英文:

I you run go install &lt;pkg&gt;, the binary will be placed in $GOPATH/bin. You can copy that binary to another machine that has the same OS and architecture.

You can also change into the directory that includes the main package and just run go build. The binary will be placed in the current directory.

There are no dependencies in a Go binary for you to track. It is statically linked. (Some system libraries may be dynamically linked, but if you are running on the same OS, this shouldn't be a problem.)

huangapple
  • 本文由 发表于 2015年5月19日 01:44:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/30309724.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定