Skip to content
COL0

How to deploy a Go (Golang) application to production

Go has a huge advantage when deploying: it compiles everything into a single binary. Even so, you need to know where to put it, how to keep it alive and how to give it HTTPS.

Written by Victor Barrera

What you need before starting

  • A Linux server with SSH and a domain.
  • Your project with go.mod and a main that reads the port and configuration from environment variables.

The steps, in short

  1. Compile for Linux from any operating system:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o myapp ./cmd/myapp
  1. Upload the binary with scp or from your pipeline and keep it in a folder such as /opt/myapp/.
  2. Create a service user without administrator permissions to run it.
  3. Define a systemd service with Restart=always and an EnvironmentFile for your environment variables.
  4. Put a proxy in front: Caddy obtains and renews the HTTPS certificate by itself; Nginx also works if you already know it.
  5. Automate: build and upload on every push with GitHub Actions and restart the service.

Common mistakes

  • Compiling with CGO enabled and the binary failing on the server because of missing libraries.
  • Using relative paths for config files or templates: the service starts from a different folder.
  • Not setting timeouts on the HTTP server.
  • Running the binary as root.

How we help

We recommend the simplest route for your case and leave it running with automatic restarts, HTTPS, logs and continuous deployment.

Frequently asked questions

Do I need to install Go on the server?

No. You compile on your computer or in your pipeline and upload only the binary. The server does not need the compiler.

Docker or a plain binary?

To start, a binary with systemd is the simplest and lightest option. Docker helps when you have several services, system dependencies, or want the same environment in development and production.

Ready to publish your project?

Book your free 30-minute session and leave with a clear plan.

Book your free session