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.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:- Create a
.gitpod.yml
- Create a custom Dockerfile
- Reference your newly created Dockerfile in your
.gitpod.yml
- Update your
.gitpod.Dockerfile
to install your preferred dependency versions
- Commit and push both
.gitpod.yml
and.gitpod.Dockerfile
- Start a new workspace from the branch with the committed
.gitpod.Dockerfile
gitpod.io/#https://github.com/gitpod-io/gitpod
- 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.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:
.gitpod.yml
configuration file, like so:
.gitpod.yml
Debugging your Go application in Gitpod
Debugging your Go applications in VS Code
Here is a quick clip on how to automatically configure debugging for Go! So, basically in this video we:- First, open the Go file that we want to debug
- Then, go to the debug menu and select “Add Configuration…”
- Next, in the dropdown choose “Go launch file”
- Finally, start debugging your Go program!
.theia/
, and inside add a file called launch.json
, finally, add the following to it:
To see a basic repository with Go debugging, please check out gitpod-samples/template-golang-cli:
Debugging your Go applications in GoLand
Steps to debug your Go application in GoLand:- Open your project in Gitpod with GoLand.
- Open the
main.go
file in the editor. - Click on the
Run
menu and selectEdit Configurations...
. - Click on the
+
button and selectGo Application
. - In the
Go Application
window, enter the name of the configuration and the path to the file you want to debug. - Click on the
Apply
button. - 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
$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
- By default, Gitpod clones the repository into the directory
/workspace
, which becomes the root directory for the workspace. WithcheckoutLocation
andworkspaceLocation
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:Repository | Description | Try It |
---|---|---|
prometheus | The Prometheus monitoring system and time series database | |
go-swagger | A simple yet powerful representation of your RESTful API | |
go-gin-app | Gin example running in Gitpod | |
gosh-terminal | A terminal implemented in Go where you can do anything |
Further Reading
- VS Code/Go Documentation The stuff here also applies to Gitpod!
- JetBrains/GoLand Documentation The stuff here also applies to Gitpod!
- VS Code/Go debugging VS Code’s Documentation on Go debugging