HeadlinesBriefing favicon HeadlinesBriefing.com

Go Programming: Setup and First Code

DEV Community •
×

JetBrains data shows Go is used by approximately 4.8 million developers, driving its adoption for high-performance backend systems. Created at Google in 2009 to fix slow compilation and complexity in C++ and Java, it offers a simpler syntax. This guide walks you through installing the language, creating a go.mod file, and writing your first program.

Start by downloading the installer from go.dev and verifying the setup with the `go version` command. Create a project directory and initialize it using `go mod init`. Inside that folder, a main.go file houses the code. Every executable starts with `package main`, imports the `fmt` library for printing, and runs the logic inside the `func main()` function.

Two primary commands drive development. Use `go run main.go` for quick testing, which executes code without creating extra files. For distribution, `go build main.go` compiles a standalone binary executable that runs on machines without Go installed. This workflow allows developers to rapidly prototype before shipping efficient, compiled software to production environments.

Go is statically typed, meaning variables require explicit data definitions like string, int, float64, and bool. Developers can declare variables using full syntax, type inference, or the short `:=` operator inside functions. Mastering these basics sets the stage for exploring conditionals and loops in future tutorials, helping new users leverage Go's speed and concurrency capabilities.