Go

Framework
Go
Category
Languages
Publisher
Jetify
{
  "packages": ["go@1.24.5"],
  "env": {
    "GOPATH": "$HOME/go/",
    "PATH":   "$PATH:$HOME/go/bin"
  },
  "shell": {
    "init_hook": [
      "export \"GOROOT=$(go env GOROOT)\""
    ],
    "scripts": {
      "run_test": "go run main.go"
    }
  }
}

Go

Go projects can be run in Devbox by adding the Go SDK to your project. If your project uses cgo or compiles against C libraries, you should also include them in your packages to ensure Go can compile successfully

Example Repo

Adding Go to your Project

devbox add go, or add the following to your devbox.json

  "packages": [
    "go@latest"
  ]

This will install the latest version of the Go SDK. You can find other installable versions of Go by running devbox search go. You can also view the available versions on Nixhub

If you need additional C libraries, you can add them along with gcc to your package list. For example, if libcap is required for your project:

"packages": [
    "go",
    "gcc",
    "libcap"
]

Setting up the Go environment

This example configures a few environment variables in devbox.json:

"env": {
    "GOPATH": "$HOME/go/",
    "PATH":   "$PATH:$HOME/go/bin"
}
  • GOPATH is set to $HOME/go, which is Go's default location. Keeping the GOPATH outside of your project directory lets the module cache ($GOPATH/pkg/mod) be shared across projects and keeps build artifacts out of your source tree.
  • Adding $GOPATH/bin to PATH makes tools installed with go install available inside the Devbox shell.

Which Go toolchain is active is determined by the go binary on PATH (here, the one provided by Nix). The init_hook sets GOROOT to match that installation, which some tooling relies on:

"shell": {
    "init_hook": [
        "export \"GOROOT=$(go env GOROOT)\""
    ]
}

Note on GOPATH: avoid setting GOPATH to your project directory (e.g. "GOPATH": "$PWD"). When a module (a directory containing go.mod) lives inside GOPATH, the Go toolchain falls back to legacy GOPATH mode and prints a warning:

go: warning: ignoring go.mod in $GOPATH /path/to/your/project

Using $HOME/go (as above) keeps module-aware builds working as expected.

README.md

Level up your dev environment

No need to switch your style. Devbox works with any coding language, so you can get results as you write.
PREPARE FOR LAUNCH

Plans for teams of any size

Jetify Cloud offers pricing plans for Solo Developers to Large Enterprises, and everything in between. All plans include free credits, and you are only billed for what you use. Need something custom? Contact our team and we can help.
YOUR INPUT COUNTS

Join the community

Discuss ideas, uses and builds with the Jetify team and others.