JSTAcademy
0 XP
Dashboard
Crash Courses
Environment & Hello World
20 min
Basic+155 XP
Crash Courses · Basic

Environment & Hello World

Install Go, configure VS Code, run your first program
20 min read+155 XP on completionCert: Go Crash Course
Tap any word in the text below to start reading from there.

Setting Up Go

1. Install Go

Download the installer for your OS from https://go.dev/dl (current LTS: 1.22+).

After installation verify:

go version
# go version go1.22.3 linux/amd64

2. VS Code Setup

Install the Go extension by the Go Team at Google (extension id: golang.go).

On first open VS Code will prompt you to install tools — click Install All. This pulls in gopls, dlv (debugger), staticcheck, and friends.

3. Your First Program

Create a directory and enter it:

mkdir hello && cd hello
go mod init example.com/hello

Create main.go:

package main

import "fmt"

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

Run it without producing a binary:

go run main.go
# Hello, World!

Build a native binary:

go build -o hello .
./hello
# Hello, World!

4. What Just Happened

Every Go source file begins with a package declaration. The main package is special — its main() function is the program entry point. The import block pulls in packages from the standard library or external modules. fmt is Go's formatting package.

Go compiles to a statically linked binary — no runtime or VM needed on the target machine. That is why Go binaries are often used for CLI tools and microservices.

5. go mod init

go mod init creates go.mod, which declares the module path and the minimum Go version. Think of it as Go's package.json. You will not need to touch it manually for simple programs, but understanding it is essential for multi-file projects.

module example.com/hello

go 1.22

6. Formatting

Go ships with an official formatter. Run it at any time:

go fmt ./...

The VS Code extension runs this on save automatically.

0%