Golang basics for beginners in 2026
Set up Go, write your first program, and build a small module with tests.

How do I start learning Golang as a beginner?
This guide gets you from Go install to a working module with tests.
Before you start
Get the latest AI news in your inbox
Weekly picks of model releases, tools, and deep dives — no spam, unsubscribe anytime.
No spam. Unsubscribe at any time.
- Go 1.22+ installed from the official Go installation docs.
- A code editor such as VS Code with the Go extension.
- A terminal on macOS, Linux, or Windows.
- A GitHub account if you plan to publish code.
- Basic command-line comfort: cd, mkdir, and running commands.
Step 1: Install the Go toolchain
Your first outcome is a working Go environment that can compile and run programs locally. Use the official installer so your PATH and GOROOT setup match the current release. If you want the source project, start from the Go GitHub repository.

go versionYou should see a version string such as go version go1.22.x. If the command is not found, reopen your terminal and verify that Go is on your PATH.
Step 2: Create your first Go file
Your next outcome is a tiny program that prints text to the terminal. Create a new folder, add a file named main.go, and place a minimal main package inside it.

package main
import "fmt"
func main() {
fmt.Println("Hello, Go")
}Run it with go run main.go. You should see Hello, Go in the terminal, which confirms that your compiler and standard library are working.
Step 3: Initialize a Go module
Your third outcome is a project that Go can manage with versioned dependencies and repeatable builds. From the project folder, initialize a module name that matches your repo or local package path.
go mod init example.com/hello-goAfter that, you should see a new go.mod file. Run go mod tidy if you add imports later; for now, the verification is simply that the module file exists and Go recognizes the folder as a module root.
Step 4: Add a function and test
Your fourth outcome is a reusable function with an automated test. This step shows the basic Go workflow: write code, write a test, and let the toolchain prove that behavior stays correct.
package main
func greet(name string) string {
if name == "" {
return "Hello, Go"
}
return "Hello, " + name
}Create a main_test.go file and run go test. You should see ok for your module, which confirms your function behaves as expected.
Step 5: Build a runnable binary
Your final outcome is a compiled executable you can ship or share. Build the program with the Go toolchain so you can confirm the output binary is created and ready to run.
go build -o hello-goYou should see a new binary named hello-go in the current directory. On Unix-like systems, run it with ./hello-go; on Windows, run hello-go.exe. The expected result is the same greeting you saw with go run.
Common mistakes
- Using an outdated Go version. Fix: install Go 1.22+ and recheck
go version. - Forgetting
package mainorfunc main(). Fix: add both so the file can run as an entry point. - Running commands outside the module folder. Fix: change into the directory that contains
go.modbefore you build or test.
What's next
Once this works, move on to structs, interfaces, slices, error handling, and HTTP servers, then publish your code to GitHub and build a small CLI or web API as your next practice project.
// Related Articles