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 versionYour 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.
Build and Run the Binary
go build hello.go
./helloWhy 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?