CodeBlanks Logo Icon CodeBlanks

Installing Go

Learn to download and install Go and the GOPATH.

Installing Go

You download Go from go.dev/dl. There are official installers for Linux, macOS and Windows. After installing, the go version command shows the installed version.

Go keeps your sources in a workspace called GOPATH. Since modules became the default in Go 1.11, GOPATH matters less; legacy projects without modules are still looked up under GOPATH.

GOROOT is Go's own install directory and is usually set automatically.

The go command

The go command is the gateway to Go. Common subcommands:

  • go run main.go: compiles and runs immediately
  • go build: produces an executable binary
  • go test: runs tests
  • go mod init: starts a new module
  • go get: downloads a dependency

Run go help to see every subcommand.

Practice Print the version

Inside main, print the text Go 1.22 with fmt.Println.

Starter code

main.go
package main

import "fmt"

func main() {
    // buraya yaz
}

Sample solution

main.go
package main

import "fmt"

func main() {
    fmt.Println("Go 1.22")
}

Expected output

Go 1.22

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is GOPATH for?

  • It points to the Go compiler directory
  • It stores executable files
  • It is the web address of Go modules
  • It is the workspace for your Go sources Correct answer

Explanation: GOPATH is the workspace for your Go sources.

2 Version command

Question
To see the installed Go version, type ____ on the command line.
Answer
To see the installed Go version, type go version on the command line.

Explanation: go version shows the installed version.

3 Match the commands

Term Meaning
go run Runs the source
go build Produces a binary
go test Runs tests
go mod init Starts a module

All lessons in Beginner