Setting Up a Go Development Environment on Mac and Running Hello World

Overview

This guide introduces how to quickly set up a Go development environment on Mac and run a Hello World program.

Installing Go

Install Go using Homebrew.

1
> brew install go

Check the installed version.

1
2
> go version
go version go1.21.3 darwin/arm64

Running Hello World

Save the following code as main.go.

1
2
3
4
5
6
7
package main

import "fmt"

func main() {
  fmt.Printf("Hello World\n")
}

Run the code.

1
2
> go run hello.go
Hello World

Build the binary and execute it.

1
2
3
4
5
6
7
> go build hello.go

> ls
hello*    hello.go

> ./hello
Hello World

Conclusion

That’s how you can set up a Go development environment on Mac and quickly run a Hello World program.