Skip to main content
Gitpod includes Go in the default image, but if you need to customize your Go version or IDE setup in Gitpod, this guide will help you.

Prerequisites

This guide assumes familiarity with: Docker, YAML, Linux, Bash and Linux environment variables.

Getting started / Quick Start

To see a full working Go application, take a look at gitpod-samples/template-golang-cli. To update an existing Go application, follow the steps below in this guide. Push

Installing Dependencies

The default base image

The default Gitpod workspace image default is workspace-full based on Ubuntu. This base image includes:
  • Go v1.19.1 (go version)
We discuss how to set up a custom base image later in the guide.

Updating Go Versions

Gitpod uses the latest stable version of Go by default. If you want to use a different version, you can use the Go Version Manager to install and manage multiple versions of Go or you can following their official guide.

Setting up a custom Dockerfile

To ensure Gitpod workspaces always start with the correct dependencies, configure a Dockerfile:
  1. Create a .gitpod.yml
  1. Create a custom Dockerfile
  1. Reference your newly created Dockerfile in your .gitpod.yml
  1. Update your .gitpod.Dockerfile to install your preferred dependency versions
  1. Commit and push both .gitpod.yml and .gitpod.Dockerfile
  1. Start a new workspace from the branch with the committed .gitpod.Dockerfile
For example, opening: gitpod.io/#https://github.com/gitpod-io/gitpod
  1. Test your dependencies are correct in the new workspace
If your changes are not taking effect, ensure your workspace is building from the correct context, where your gitpod.yml or gitpod.Dockerfile are checked in to version control and are on the branch or commit that you are opening.
See configure Docker for more.

Using the dep dependency manager in Gitpod

If your project uses the dep (deprecated - v0.5.4) dependency manager then you need to add a .gitpod.Dockerfile to your project. A basic example that extends the default workspace image might be something like:
Also, don’t forget to reference the above Dockerfile in your .gitpod.yml configuration file, like so:
.gitpod.yml

Debugging your Go application in Gitpod

Debugging your Go applications in VS Code

To automatically configure debugging for Go:
  1. First, open the Go file that we want to debug
  2. Then, go to the debug menu and select “Add Configuration…”
  3. Next, in the dropdown choose “Go launch file”
  4. Finally, start debugging your Go program!
You can also create the Go debug configuration file manually To start debugging your Go application in Gitpod, please create a new directory called .theia/, and inside add a file called launch.json, finally, add the following to it:
Then, simply open the Go file you want to debug, open the Debug panel (in the left vertical toolbar, click the icon with the crossed-out-spider), and click the green “Run” button.
To see a basic repository with Go debugging, please check out gitpod-samples/template-golang-cli: Open in Gitpod

Debugging your Go applications in GoLand

Steps to debug your Go application in GoLand:
  1. Open your project in Gitpod with GoLand.
  2. Open the main.go file in the editor.
  3. Click on the Run menu and select Edit Configurations....
  4. Click on the + button and select Go Application.
  5. In the Go Application window, enter the name of the configuration and the path to the file you want to debug.
  6. Click on the Apply button.
  7. Click on the Debug button to start debugging your Go application.

Using $GOPATH

Older Go projects without module support need a specific workspace layout: the source code of your repository and its dependencies must be in the directories
in the $GOPATH. Using the .gitpod.yml file, you can bring about such a workspace layout. Here is how we do that for the example go-gin-app repository:
.gitpod.yml
In more detail:
  • By default, Gitpod clones the repository into the directory /workspace, which becomes the root directory for the workspace. With checkoutLocation and workspaceLocation you can change this behavior (the paths are taken relative to /workspace).
  • Gitpod preconfigures the $GOPATH environment variable to include the directory /workspace/go.
  • With go get -v ./... we retrieve the sources of the dependencies from GitHub.
  • To build the app, we run go build -o app.
  • Lastly, we start the application.

Example Repositories

Here are a few Go example projects that are already automated with Gitpod:

Further Reading