Go

How Anvil runs Go projects, installs Go versions and keeps Go's caches in its own folder.

What Anvil detects

A folder with a go.mod. PHP and Rust are recognized first; see the detection table.

Anvil runs go run . on a private port passed in $PORT and proxies <name>.test to it. The program must listen on that port, on 127.0.0.1.

Installing Go

Settings › Languages › Go › Install, or with the full release:

anvil runtime list
anvil runtime install go 1.27.2

Releases are those go.dev lists, checked against go.dev's SHA-256 and unpacked into ~/.anvil/runtimes/go/<version>.

Choosing the version

No default: the newest installed version, unless pinned with anvil app runtime myapi 1.27.2 or Go version in the Settings tab. anvil app runtime myapi goes back to automatic. GOTOOLCHAIN=local stops Go from downloading other toolchains.

Running an application

The server doesn't start on its own: Start in the Dev tab, or anvil app start myapi while the desktop app is open (this also starts dev processes marked Dev start). To start it with Anvil, turn on Start with Anvil in Settings or run anvil app autostart myapi true (off by default; with the CLI alone, restart anvil start). It runs until stopped or Anvil quits; while stopped, <name>.test shows a "not running" page.

Start command and port: Start command and Port in Settings, or:

anvil app command myapi 'go run ./cmd/server'
anvil app port myapi 41500

No value resets to the default. The automatic port is derived from the name, in 41000–44999, moving up on collision. A program with a fixed port: set that port with anvil app port myapi <port> or Port.

VariableValue
PORTThe application's private port
HOST, HOSTNAME127.0.0.1
GOROOT~/.anvil/runtimes/go/<version>
GOPATH~/.anvil/cache/go
GOCACHE~/.anvil/cache/go-build
GOTOOLCHAINlocal
PATH~/.anvil/runtimes/go/<version>/bin first

In your terminal

No go terminal command. Anvil's is ~/.anvil/runtimes/go/<version>/bin/go; set the variables above to use Anvil's caches.

Caches and files

Modules and build cache go to ~/.anvil/cache/go and ~/.anvil/cache/go-build; ~/go is untouched. Anvil writes nothing into a Go project.

Go's local telemetry counters stay in ~/Library/Application Support/go/telemetry, shared with your own Go (nothing is uploaded unless you ran go telemetry on). Moving it would require changing HOME, hiding ~/.gitconfig, ~/.netrc and Go settings from builds. anvil uninstall doesn't remove it.

New applications

anvil new go myapi

Or New… (⌘N) in the app, under Other. Needs Go installed. Writes a main.go that answers "Hello from Go" on $PORT and runs go mod init <name>. Takes --git/--no-git and --https/--no-https; see New applications.

Differences from production

  • go run . builds and runs on each start; no separate build step.

Removing a version

Hover the version in Settings › Languages › Go and click Uninstall, or anvil runtime uninstall go 1.27.2. This deletes ~/.anvil/runtimes/go/1.27.2; unpinned applications use the newest remaining version on next start.

Anvil refuses while applications are pinned to it ("blog, shop use Go 1.27.2 — switch them to another version first"); Settings then shows Pinned by with their names instead of Uninstall. Unpin: set Go version to Automatic or another version, or run anvil app runtime blog without a version (with only one version installed the field is disabled; use the command).

On this page