PengyOS / Docs / Recipes / Go

Go

Go builds pure-Go programs with its own linker, so unlike C or Rust it works right on the PengyOS host. Install the official toolchain into your home directory and you're set.

ServerDesktop

Install the toolchain

GOV=$(curl -fsSL 'https://go.dev/VERSION?m=text' | head -1)     # e.g. go1.27.1
mkdir -p ~/.local && rm -rf ~/.local/go
curl -fsSL "https://go.dev/dl/$GOV.linux-amd64.tar.gz" | gzip -dc | tar -xf - -C ~/.local

Put it on your PATH. Add this to ~/.zshrc, then open a new terminal:

path=(~/.local/go/bin ~/go/bin $path)
go version

To upgrade, run the same three lines again. Your modules and ~/go are kept.

Build something

mkdir -p ~/src/hello-go && cd ~/src/hello-go
go mod init example.com/hello
cat > main.go <<'EOF'
package main

import "fmt"

func main() { fmt.Println("hello from PengyOS") }
EOF
go run .
go build -o hello . && ./hello

Tools install into ~/go/bin:

go install github.com/charmbracelet/glow/v2@latest
glow README.md

cgo

With no C compiler on the host, Go turns cgo off by itself (go env CGO_ENABLED prints 0). That gives you static binaries, and almost everything builds that way, including net/http, TLS, and SQLite through modernc.org/sqlite. A package that truly needs C (mattn/go-sqlite3, GUI bindings) fails with build constraints exclude all Go files or cgo: C compiler not found. Build that one in the dev box, which has gcc:

pengyos-guest enter dev -- sh -c 'cd ~/src/myapp && CGO_ENABLED=1 ~/.local/go/bin/go build'

The box can use the same ~/.local/go, since it shares your home. Its own golang package is Ubuntu 24.04's older Go.

← Rust with rustupllama.cpp →