Chapter 1. Setting Up Your Go Environment
Every programming language needs a development environment, and Go is no exception. If you’ve already written a Go program or two, you should have a working environment, but you might have missed out on some of the newer techniques and tools. If this is your first time setting up Go on your computer, don’t worry; installing Go and its supporting tools is easy. After we set up our environment and verify it, we’ll build a simple program, learn about the different ways to build and run Go code, and then explore some tools and techniques that make Go development easier.
Installing the Go Tools
To write Go code, you first need to download and install the Go development tools. The latest version of the tools can be found at the downloads page on the Go website. Choose the download for your platform and install it. The .pkg installer for Mac and the .msi installer for Windows automatically install Go in the correct location, remove any old installations, and put the Go binary in the default executable path.
Tip
If you are a Mac developer, you can install Go using Homebrew with the command brew install go. Windows developers who use Chocolatey can install Go with the command choco install golang.
The various Linux and FreeBSD installers are gzipped tar files and expand to a directory named go. Copy this directory to /usr/local and add /usr/local/go/bin to your $PATH so that the go command is accessible:
$ tar -C /usr/local -xzf go1.15.2.linux-amd64.tar.gz ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access