Dev Skills

Setup, your first program, and the toolchain

Install Go, run one file, and meet the four commands you will use every day.

Topic 1 of 98 · 5 min to read · 45 min to build
After this topic you can
  • Write and run a package main program with go run ..
  • Explain what the zero value of an int, a string and a bool is.
  • Predict what go build, go fmt and go vet each do before you run them.

Go is a compiled language. You write a .go file, the compiler turns it into a single machine-code binary, and you run that. There is no interpreter to install on the server and no virtual machine. That one fact explains most of what people like about Go: you build one file and copy it anywhere.

First, install it. Pick your system below. Every option installs the same thing: the compiler, the standard library and the go command.

terminal
go version
# go version go1.25.1 linux/amd64

Install Go

macOS
# with Homebrew (easiest)
brew install go
# or download the .pkg installer from https://go.dev/dl/
# and double-click it
Windows
# with winget
winget install GoLang.Go
# or download the .msi installer from https://go.dev/dl/
# then close and reopen your terminal so PATH updates
Linux
# the official way — distribution packages are often far behind
curl -LO https://go.dev/dl/go1.25.1.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.25.1.linux-amd64.tar.gz
# then add Go to your PATH, and reload your shell
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
source ~/.profile
Check https://go.dev/dl/ for the current version number before you copy that URL.
check it worked
go version
# go version go1.25.1 linux/amd64
go env GOPATH
# /home/you/go — where downloaded packages live. You rarely need to touch it.
Note: Nothing else to install. No package manager to set up, no virtual environment, no build tool. The go command does all of it.

You can also run Go without installing anything

Every code block on this site with a ▶ Run button executes on the official Go Playground, so you can work through the language topics in a browser before you install anything. Press Run, change the code, press Run again.

You will need a real installation from the practice projects onwards, because those use files, folders and a database. The playground has none of them.

A module is a project

Every Go project is a module. A module is a folder with a go.mod file at the top. That file records the module name and which Go version it needs. You make one once, at the start.

terminal
mkdir -p ~/go-learn/d01
cd ~/go-learn/d01
go mod init d01
The name `d01` is the import path. For real projects use something like `github.com/you/project`.

The first program

Every Go file starts with package. A program you can run lives in package main and has a func main(). That function is where execution starts, and when it returns the program exits.

main.go
package main
import "fmt"
func main() {
fmt.Println("hello")
name := "sahdev" // short declaration, the type is inferred
var age int = 25 // the long form, type written out
var city string // no value given, so it gets the zero value: ""
const pi = 3.14 // fixed at compile time, cannot change
fmt.Println(name, age, city, pi)
}

Three ways to declare, one you will mostly use

  • name := "sahdev" — inside a function, the common case. Go works out the type.
  • var age int = 25 — when you want the type written down, or you are outside a function.
  • var city string — declare now, assign later. It holds the zero value until you do.
  • const pi = 3.14 — a value fixed at compile time. It cannot be changed and has no address.

Zero values: Go has no "undefined"

This is the first idea that makes Go different from JavaScript or Python. A variable you declare but do not set is not empty, null, or undefined. It holds a well-defined zero value for its type.

TypeZero value
int, float640
string"" (empty, not nil)
boolfalse

Because of this you never get a "cannot read property of undefined" style crash from an unset variable. The other types you will meet later also have zero values, and each lesson says what they are.

The four commands

terminal
go run . # compile and run, leave no binary behind
go build -o app . # produce ./app, ready to copy to a server
go fmt ./... # format the code. Not a preference, the standard.
go vet ./... # find real mistakes the compiler allows
Note: Go has one formatting style, and go fmt applies it. Tabs, brace placement and spacing are decided for you, so a Go team has nothing to argue about there. Most editors run it on save; if yours does not, run it before every commit.

Try it yourself

press Run — this executes on the Go Playground
package main
import "fmt"
func main() {
name := "sahdev" // short declaration, the type is inferred
var age int = 25 // the long form, type written out
var city string // never assigned, so it holds the zero value
const pi = 3.14 // fixed at compile time
fmt.Println(name, age, city, pi)
fmt.Printf("city is %q and has %d characters\n", city, len(city))
}
Press Run. Then change a value, or add a line, and run it again.

Build this: your first win

A tiny program that does a real job: split a bill. Put it in main.go in your d01 folder and run go run .. Then change the numbers and run it again.

main.go — split a bill
package main
import "fmt"
func main() {
total := 84.50
people := 4
share := total / float64(people)
fmt.Println("Total:", total)
fmt.Println("People:", people)
fmt.Println("Each pays:", share)
}
`float64(people)` turns the whole number into a decimal so the two can be divided. **Type conversion** explains why Go makes you write that.
The short version
  • A module is a folder with a go.mod. A runnable program is package main with func main().
  • Every variable has a zero value. There is no undefined, and no unset variable to guard against.
  • := inside functions, var when you want the type written down or you are at package level.
  • go run, go build, go fmt, go vet. That is the whole daily toolchain.
Remember: Go compiles to one self-contained binary with nothing to install beside it, and every variable starts at a defined zero value. Those two facts shape most of the language.
Build this before moving on
Print your name, age, and whether you are a student, using all three declaration styles. Then declare a variable of each basic type without assigning it and print them, to see the zero values yourself.
Then try these in your own editor
  1. 1Make a second file in the same folder, put a function in it, and call that function from main. Notice you did not need an import.
  2. 2Delete the fmt import while still calling fmt.Println, and read the error. Then add an unused variable and read that one too.
  3. 3Build with go build -o app . and run ./app. Copy the binary to another folder and run it there — nothing else needed.
Check yourselfTake the Getting started test