TExcelTAD
Home › Go › Go Get Started

Go Get Started

You can run every example in this course right here in the browser. Sooner or later, though, you will want Go on your own computer. This chapter shows how to install it, create a project and run it.

Install Go

  1. Download the installer for your system from the official site, go.dev/dl.
  2. Run it (Windows .msi, macOS .pkg) or, on Linux, unpack the archive into /usr/local and add /usr/local/go/bin to your PATH.
  3. Open a new terminal and check the version:
bash
go version
go version go1.25.0 linux/amd64

Your version number and platform may differ — anything from Go 1.22 upward works for this course.

Note: You also want an editor with Go support. VS Code with the official Go extension is a popular free choice; it formats your code on save and shows errors as you type.

Create a module

Go code is organised in modules. A module is a folder with a go.mod file that records the module's name and the Go version it needs. Create a folder and initialise a module inside it:

bash
mkdir hello
cd hello
go mod init example.com/hello
go: creating new go.mod: module example.com/hello

The module path (example.com/hello) is just a unique name. For code you publish it is usually the repository URL, e.g. github.com/yourname/hello. The generated go.mod looks like this:

text
module example.com/hello

go 1.25.0

Write the program

Create a file called main.go in the same folder:

go · try it yourself
package main

import "fmt"

func main() {
	fmt.Println("Hello from my first Go module!")
}
Hello from my first Go module!

Run it

go run compiles the program into a temporary location and runs it immediately — perfect while you are developing:

bash
go run .
Hello from my first Go module!

The . means "the package in the current folder". You can also name a file: go run main.go.

Build an executable

go build compiles your program into a standalone executable file that you can copy to another machine with the same operating system — no Go installation needed there.

bash
go build
ls
./hello
go.mod  hello  main.go
Hello from my first Go module!

On Windows the file is called hello.exe.

The most useful go commands

Command What it does
go run . compile and run the package in the current folder
go build compile to an executable
go mod init <path> start a new module
go mod tidy add missing and remove unused dependencies in go.mod
go fmt ./... format all Go files in the module
go vet ./... report suspicious code
go test ./... run the tests
go doc fmt.Println show documentation for a symbol

A second program

Programs can import more than one package. Here strings is used to convert text to upper case.

go · try it yourself
package main

import (
	"fmt"
	"strings"
)

func main() {
	name := "gopher"
	fmt.Println("Hello,", strings.ToUpper(name))
}
Hello, GOPHER

Notice the grouped import in parentheses — that is how Go code imports several packages. gofmt sorts them alphabetically for you.

Tip: Run go fmt (or let your editor do it) before every commit. Nobody in the Go community argues about tabs vs. spaces — the tool decides, and it uses tabs.

Test yourself

Which command creates a new go.mod file?

  1. go new
  2. go mod init
  3. go create
  4. go build

What is the difference between go run and go build?

  1. There is none
  2. go run compiles and runs immediately; go build writes an executable file
  3. go build runs tests
  4. go run only works on Linux