Skip to content
Search Fedora

    Browse this documentation

    Installing Go on Fedora: 1.27 and a domestic module proxy

    Terminal window
    sudo dnf install golang
    go version
    go version go1.27.1-X:nodwarf5 linux/amd64

    X:nodwarf5 is Fedora’s build tag (DWARF stripped to cut package size); the compiler matches upstream 1.27.1.

    Where the go binary, GOROOT and the module cache live

    Terminal window
    go env GOPATH GOMODCACHE GOPROXY
    • GOPATH: workspace, ~/go by default
    • GOMODCACHE: module cache, ~/go/pkg/mod
    • GOPROXY: module proxy, https://proxy.golang.org,direct

    proxy.golang.org frequently times out here. Replace it:

    Terminal window
    go env -w GOPROXY=https://goproxy.cn,direct

    direct is the fallback for modules the proxy lacks. Verify:

    Terminal window
    go env GOPROXY
    https://goproxy.cn,direct

    go env -w writes ~/.config/go/env, not a shell variable, so it survives new terminals.

    Terminal window
    mkdir -p ~/hello && cd ~/hello
    go mod init example.com/hello
    cat > main.go <<'EOF'
    package main
    import "fmt"
    func main() {
    fmt.Println("hello from Go")
    }
    EOF
    go run main.go
    hello from Go

    Build a binary:

    Terminal window
    go build -o hello .
    ./hello
    Terminal window
    go install golang.org/x/tools/cmd/goimports@latest

    Binaries land in $GOPATH/bin (~/go/bin), which is not on PATH by default:

    Terminal window
    echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.bashrc
    source ~/.bashrc
    SituationChoice
    learning, building existing projects, CIdnf install golang is enough; upgrades follow Fedora
    an exact patch release (1.26.3)upstream tarball or go install golang.org/dl/go1.26.3@latest
    several versionsupstream tarballs in separate directories, switch via PATH

    Upstream:

    Terminal window
    cd /usr/local
    sudo curl -LO https://go.dev/dl/go1.27.1.linux-amd64.tar.gz
    sudo tar xzf go1.27.1.linux-amd64.tar.gz
    export PATH=/usr/local/go/bin:$PATH
    go version
    SymptomCause
    go: cannot find main modulenot inside a module; run go mod init first
    module downloads hangGOPROXY still points at the official proxy
    binary missing after go install~/go/bin not on PATH
    permission denied while buildingbuilding inside /usr; work in your home directory
    conflict with the repository buildtwo go binaries on PATH; check which -a go