Chapter 3: Go Getting Started

What “Getting Started with Go” Actually Is

  • Goal: Get Go installed → write/run first code → understand modules (modern dependency system) → call code from an external library.
  • Time: 10–20 minutes if you follow along.
  • Teaches: go command basics, go.mod, go run, importing third-party modules, pkg.go.dev discovery.
  • Current as of Feb 2026: Works with Go 1.26.0 (latest stable from go.dev/dl — released late 2025 / early 2026).

Step 0: Install Go (if not done yet)

Go to https://go.dev/dl → download Go 1.26.0 (or newer if a patch dropped today).

  • Linux (most common in Hyderabad dev setups):

    Bash

    Add to PATH (put in ~/.bashrc or ~/.zshrc):

    Bash
  • macOS: Use the .pkg installer or Homebrew (brew install go).

  • Windows: .msi installer → it adds to PATH automatically.

Verify:

Bash

Step 1: Create Your First Project Folder

Open terminal (PowerShell / cmd on Windows, or bash/zsh):

Bash

→ Why a new folder? Go projects live in directories. Each directory = one package.

Step 2: Initialize a Go Module (Super Important — 2026 Standard)

Bash

Output:

text

→ A file go.mod appears:

Go

Why this matters:

  • Before Go 1.11 → code had to live in $HOME/go/src/…
  • Now → anywhere. Modules let Go track dependencies + versions.
  • example/hello is a fake path (for local learning). Real projects use github.com/webliance/myapp.

Step 3: Write Your First Go File — hello.go

Create file hello.go (use VS Code — install Go extension by Go Team at Google — it auto-formats + gives hints).

Go

Key lines explained:

  • package main → This package can have a main() function → becomes executable.
  • import “fmt” → Standard library package for printing.
  • func main() → Program starts here (like public static void main in Java).

Step 4: Run It! (Easiest Way)

Bash

(. means “current directory”)

Output:

text

→ go run = compile in memory + execute immediately. Great for quick tests.

Alternative:

Bash

Step 5: Add an External Package (The Cool Part)

The tutorial uses a famous quote package by Russ Cox (rsc.io/quote).

  1. Go to https://pkg.go.dev → search “quote” → find rsc.io/quote (v1.5.2 or later in 2026).
  2. Update hello.go:
Go
  1. Download & lock the dependency:
Bash

Output something like:

text

→ Now you have:

  • go.mod updated with require rsc.io/quote v1.5.2
  • New file go.sum (checksums for security)
  1. Run again:
Bash

Output:

text

→ Classic Go proverb! You just used someone else’s code — zero hassle.

Common Mistakes Beginners Make (I’ll Save You Time)

  • Forgot go mod init → go run complains about modules.
  • Typed import rsc.io/quote without quotes → syntax error.
  • Ran go run hello.go instead of go run . → may miss module context sometimes.
  • Old tutorials say GOPATH — ignore them in 2026.
  • No internet? go mod tidy fails — need connection first time.

What You’ve Learned So Far (Summary Table)

Concept Command / Code Why It Matters in 2026
Installation Download from go.dev/dl Gets latest tools
Module init go mod init example.com/name Enables dependencies
Running code go run . Fast dev loop
Building binary go build Creates deployable exe
External packages import “rsc.io/quote” + go mod tidy Real-world code reuse
Package discovery pkg.go.dev Find libraries fast

Next After This Tutorial?

  1. Finish the official series → https://go.dev/doc/tutorial/create-module (builds a real greetings library + caller app)
  2. Go back to interactive Tour → https://go.dev/tour (do More Types + Methods)
  3. Try a tiny project: CLI tool that fetches weather (use external API + net/http)

Ready to open terminal and do this right now? Paste any error you get — we’ll debug live.

Or tell me: want to jump to slices/maps? error handling? a tiny HTTP server next?

You’re killing it — let’s keep the momentum! 💪🇮🇳

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *