Download the appropriate package for your operating system and architecture from the Go download page (https://golang.org/dl/):
- For macOS X: Download the goVersion.darwin.amd64.pkg file and follow the installation prompt. You may need to restart any open Terminal sessions for the change to take effect.
- For Windows: Download the MSI installer and follow the wizard. The installer will set up environment variables for you.
- For Linux: Open a new terminal session and type the following commands (at the time of writing, the current version is 1.10):
curl https://golang.org/doc/install?download=go1.10.1.linux-amd64.tar.gz -O /tmp/go1.10.tar.gz
tar -C /usr/local -xzf /tmp/go1.10.tar.gz
The previous commands will download the latest Go package using curl. Then, it will use tar to unpack the package. Next, add the /usr/local/go/bin to the PATH environment variable by adding the following line to your shell's profile script:
export PATH=$PATH:/usr/local/go/bin
If you install Go in a custom directory, rather than /usr/local, you must set the GOROOT environment variable to point to the directory in which it was installed:
export GOROOT=PATH/go
export PATH=$PATH:$GOROOT/bin
Then you have to reload the user profile to apply the changes:
$ source ~/.bash_profile
Now that Go is properly installed and the paths are set for your machine, let's test it out. Create a workspace on which we will build our serverless applications throughout the book:
mkdir -p $HOME/go/src
To validate that the Go workspace is configured correctly, you can run the go env command:

If the GOPATH variable is set, you're ready to go. Within the workspace, create a main.go file using vim with the following content:
package main
import "fmt"
func main(){
fmt.Println("Welcome to 'Hands-On serverless Applications with Go'")
}
Compile the file with the following command:
go run main.go
The file will show Welcome to 'Hands-On serverless Applications with Go' if it runs successfully; this shows that Go is compiling files correctly.
Go is a compiled language, and hence you can generate a single binary for your application using the following command:
go build -o app main.go
If you want to build an executable for a specific OS and architecture, you can override the GOOS and GOARCH parameters:
GOOS=linux GOARCH=amd64 go build -o app main.go
Editing Go using the vim text editor is not optimal; therefore, in the next section, I will show you how to use VSCode as a Go editor to enhance your development productivity/experience.