1. Installing Go 1.24
macOS
# Using Homebrew (recommended)
brew install go
# Verify installation
go version # go1.24.x darwin/arm64
Ubuntu / Debian
# Download and extract
wget https://go.dev/dl/go1.24.2.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.24.2.linux-amd64.tar.gz
# Add to PATH (append to ~/.bashrc or ~/.zshrc)
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$(go env GOPATH)/bin
# Verify
go version
Windows
# Using Scoop
scoop install go
# Or download the MSI installer from https://go.dev/dl/
# Verify
go version
π Version Check Comparison
Python: python3 --version |
Node.js: node -v |
Go: go version
2. GOPATH & Go Modules
Since Go 1.16, Go Modules is the default dependency management system. You no longer need to work inside GOPATH.
Initialize a Module
mkdir myproject && cd myproject
go mod init github.com/yourname/myproject
This creates a go.mod file:
module github.com/yourname/myproject
go 1.24
Common Module Commands
go mod tidy # Add missing and remove unused modules
go mod download # Download dependencies to local cache
go get pkg@v1.2 # Add or upgrade a specific dependency
π Dependency Management Comparison
Node.js: npm init → package.json
PHP: composer init → composer.json
Python: pip freeze → requirements.txt
Go: go mod init → go.mod
3. Hello World
Create main.go:
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
fmt.Printf("Go version: %s\n", "1.24")
}
Run directly
go run main.go
# Output: Hello, Go!
Build and Run
# Compile to binary
go build -o myapp main.go
# Run the binary
./myapp
π‘ go run compiles and runs in one step (for development). go build produces a standalone binary with no external dependencies.
π Run Command Comparison
Python: python main.py |
Node.js: node index.js |
Go: go run main.go
4. VS Code Configuration
Essential Extension
Install the official Go extension by the Go team. It provides:
- gopls β Language server for autocomplete, go-to-definition, refactoring
- Delve β Debugger with breakpoints, variable inspection, step-through
- Auto-formatting on save with
goimports - Linting, testing integration, and code generation
Recommended settings.json
{
"go.useLanguageServer": true,
"go.lintTool": "golangci-lint",
"go.lintOnSave": "package",
"go.formatTool": "goimports",
"editor.formatOnSave": true,
"[go]": {
"editor.defaultFormatter": "golang.go",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}
π‘ When you first open a Go file, VS Code will prompt you to install Go tools. Click "Install All" to set up gopls, dlv, staticcheck and other tools automatically.
π Chapter Summary
Go 1.24
Install via Homebrew, official tarball, or Scoop. Verify with go version.
Go Modules
go mod init creates go.mod. Use go mod tidy to manage dependencies.
go run vs go build
go run for quick execution; go build produces a standalone binary.
VS Code + gopls
The Go extension + gopls gives you autocomplete, diagnostics, and refactoring.
Delve Debugger
Set breakpoints, inspect variables, and step through code in VS Code.
Static Binary
Go compiles to a single binary β no runtime needed. Perfect for deployment.