Go

An open source programming language built to craft simple, reliable, and efficient software.

Go on Fedora

Quoting the upstream documentation:

The Go programming language is an open source project to make programmers more productive.

Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It’s a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.

Go installation

To install the Go tools, type on a terminal:

$ sudo dnf install golang

The go and gofmt binaries will become available on the system.

Go code lives in a workspace which is defined by the GOPATH environment variable. A common choice among developers, and the default value of GOPATH starting from the Go 1.8 release, is to use $HOME/go:

$ mkdir -p $HOME/go
$ echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc
$ source $HOME/.bashrc

Check that GOPATH is set correctly with this command:

$ go env GOPATH
/home/user/go

Where ‘user’ will be your user name.

Writing Go programs is covered in Go programs.

Fedora Specific Notes

Fedora 43 and newer

Starting with Go 1.25 in Fedora 43, The default values of GOPROXYand GOSUMDBas provided by the Go development team are retained. These defaults are: GOPROXY=https://proxy.golang.org,direct and GOSUMDB=sum.golang.org. To restore the previous behavior, set “GOPROXY=direct” and “GOSUMDB=off”.

The GOTOOLCHAIN environment variable is set to GOTOOLCHAIN=local. We change this default from auto to local so that the distribution-packaged Go toolchain is always used and go doesn’t automatically download pre-compiled alternative versions.

Fedora 42 and older

The standard rpm-based installation of Go on Fedora contains changes to the default values of GOPROXY, GOSUMDB, and GOTOOLCHAIN environment variables that Go developers should be aware of. The go command and related tools make extensive use of environment variables for configuration. Default values are set globally in /usr/lib/golang/go.env, and can be overridden on per user or per project basis.

For extensive help and information see:

$ go help environment

Installing the latest version

Fedora avoids making major software updates within a stable release. This means each Fedora version typically includes just one major version of Go.

Sometimes, when a Go version reaches end-of-life (EOL), the Go Special Interest Group (SIG) will try to update the current Fedora version to the next stable Go release.

If you need the newest version of Go right away, you can use the special repository maintained by the Go SIG. To enable it, run these commands in your terminal:

$ dnf copr enable @go-sig/golang-rawhide
$ dnf update golang

This will give you the most recent version of Go, even if it’s not in the regular Fedora updates yet.

GOPROXY

The value of GOPROXY in $GOROOT/go.env is set to direct. A value of direct disables access to the module mirror. See https://proxy.golang.org for more information on GOPROXY and the module mirror. A project specific go.env can override this setting. A user specific override can be set with:

$ go env -w GOPROXY=https://proxy.golang.org,direct

GOSUMDB

The value of GOSUMDB in $GOROOT/go.env is set to off replacing the default value of sum.golang.org. The GOSUMDB environment variable identifies the name of the checksum database used to help validate downloaded modules. A project specific go.env can override this setting. A user specific override can be set with:

$ go env -w GOSUMDB=sum.golang.org

GOTOOLCHAIN

Go 1.21 introduces GOTOOLCHAIN which facilitates project specific choices for the Go language toolchain of compiler, standard library, assembler, and other tools. The value of GOTOOLCHAIN is set to local instead of the default auto. When GOTOOLCHAIN is set to local, the go command always runs the bundled Go toolchain. See the Go Toolchain documentation for more information on toolchains in Go. A project specific go.env file can override this setting. A user specific override can be set with:

$ go env -w GOTOOLCHAIN=auto

References


Authors: Adam Samalik, Brad Smith, Bradley G Smith, Rodolfo Carvalho, Álex Sáez