Install Go, write hello world, understand go run vs go build.
Install Go & Run Hello World
Go (sometimes written Golang because "go" is hard to search for) is a small, fast, compiled language made at Google in 2007. The whole spec fits on a few pages — and yet it's powerful enough to write web servers, CLIs, Kubernetes, Docker, and most of the modern cloud.
What makes it stand out:
- Fast compiler — a million-line codebase builds in seconds, not minutes.
- Single binary output —
go buildproduces one file you can copy and run. - Built-in concurrency — goroutines and channels make parallel code readable.
- Tiny syntax — about 25 keywords. You can fit the language in your head.
- Excellent tooling — formatter, linter, tests, docs, profiler all in
go ....
Install
Pick one:
- Official installer: download from go.dev/dl.
- macOS:
brew install go - Linux (apt):
sudo apt install golang-go(or use the official tarball) - Windows: download the MSI from go.dev/dl
Verify the install:
go version
# go version go1.23.x linux/amd64
If you also want to know where Go put things and how it's configured:
go env GOROOT GOPATH GOBIN
GOROOT— where the Go toolchain itself lives (set automatically).GOPATH— where downloaded modules and installed binaries go (default:~/go).GOBIN— wherego installputs binaries. Add this to your$PATH.
Your first program
This is the entire program — no class, no boilerplate, no main method buried
inside an object.
What every piece does:
package main— every Go file belongs to a package. The special namemainmeans "this file produces an executable program". Libraries use any other name.import "fmt"— bring in the standard library's formatting package.fmtreads "fumpt" if you say it out loud; nobody knows why.func main()— the entry point. When you run the program, Go calls this function.fmt.Println(...)— print a line. The dot means "from thefmtpackage".
A note on go.mod
Real Go programs always live inside a module — a folder with a go.mod file
at the top. To turn a fresh folder into one, run once:
mkdir hello && cd hello
go mod init example.com/hello # any unique path works
That creates go.mod. After that, go run . and friends just work. We come back
to modules properly in the next-but-one lesson.
Running Go locally
You have three tools you'll use every day:
| Command | What it does |
| ------------- | ----------------------------------------------------------- |
| go run . | Compile and execute the current directory's program. |
| go build | Compile to a binary you can ship (a single file, no JVM). |
| go test ./... | Run every test under the current module. |
$ go run .
hello, world
$ go build -o hello
$ ./hello
hello, world
go run is a quick "compile and execute and throw the binary away" — handy while
you're iterating. go build keeps the binary so you can ship it.
The binary is statically linked: it has no runtime dependencies. You can copy it to a server that doesn't have Go installed and it still works. This is one of the big reasons people pick Go.