Any compiled language needs, first and foremost, a compiler. The Go toolchain was initially written in C. Since Go 1.3, it’s written directly in Go, following the principle of eating your own dog food. As everything is open source, you can at any time suggest improvements or look into the standard library’s source code for how other developers write their Go.
A.1 Install
Start by visiting the Go website for a simple explanation (did we tell you that Go aims for simplicity?) of how to download the installer and run it on Linux, Mac, or Windows. Follow the installation steps (https://go.dev/doc/install), and don’t forget to add go
to your path.
There is no good reason to pick old versions. Just for the record, we’re writing this book using Go 1.23.
A.2 Check
As mentioned in the online installation guide, you can check the version of Go that you’re using and also verify that Go is properly installed by running the command shown in the following listing in any directory.
A.3 Go’s environment variables
Under the hood, Go uses several variables without being explicit about it. In this section, we’ll look closely at two of these variables: GOROOT
and GOPATH
.
If you’ve just installed Go, these variables won’t be set in your sessions. If you’re questioning why Go uses them if they’re not set, the answer is that Go is able to use default values for these variables.