Go Get Started

Get Go installed on your machine, then write and run your very first Go program.

Installing Go

Go is distributed as a free installer from go.dev/dl for Windows, macOS, and Linux. Download the package for your operating system, run the installer, and it will place the go command on your system PATH automatically.

  • Download the installer that matches your operating system
  • Run the installer and accept the default installation location
  • Open a new terminal window so the updated PATH is loaded
  • Verify the install by checking the installed version

Check Your Installation

go version
Note: If the go command is not found after installing, restart your terminal — many shells only reload the PATH environment variable in new sessions.

Your First Go File

Go source files always end in the .go extension. Create a file named hello.go and add the following code.

hello.go

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

Running Your Program

The go run command compiles and immediately executes a source file in one step, which is perfect while you are developing. The go build command instead compiles your code into a standalone executable file that you can run later, without needing Go installed.

CommandWhat It DoesBest For
go run hello.goCompiles and runs immediately, no file left behindQuick testing during development
go build hello.goProduces a standalone binary you can distributeSharing or deploying a finished program

Build and Run the Binary

go build hello.go
./hello
Note: Use go run constantly while learning — it saves you from having to clean up compiled binaries after every small change.

Why package main Matters

Only a file declared as package main, containing a func main, produces a runnable program. Every other package in Go is a library meant to be imported, not executed directly.

Exercise: Go Get Started

Which command displays the installed Go version?