Go for Beginners: Install Go and Write Your First Program
Introduction
Go is a fast, simple, compiled language created at Google, widely used for cloud services, command-line tools, and networked software. This tutorial takes you from installation to running and building your first program.
Prerequisites
- A computer running Windows, macOS, or Linux
- Access to a terminal or command prompt
Step-by-Step Guide
Step 1: Install Go
Download the installer for your operating system from go.dev/dl and run it. The installer adds the go command to your PATH.
Step 2: Verify the installation
Open a new terminal and check the installed version.
go versionStep 3: Create a module
A module is a Go project with a go.mod file that tracks its name and dependencies.
mkdir hello
cd hello
go mod init example.com/helloStep 4: Write your first program
Create main.go. Every executable program lives in package main and starts at the main function.
package main
import "fmt"
func main() {
fmt.Println("Hello, CaliberTek!")
}Step 5: Run and build
go run compiles and runs in one step. go build produces a standalone executable you can copy to another machine of the same operating system.
go run .
go buildFAQs
- Do I need to set GOPATH?
- Not for modern Go. Since modules were introduced you can create projects anywhere and manage dependencies with go.mod.
- Why is Go popular for backend and cloud tools?
- It compiles quickly to a single static binary, has built-in concurrency features, and keeps the language small and easy to read.
Summary
Install Go, create a module with go mod init, and use go run and go build. From here, learn variables, functions, slices, maps, structs, and goroutines.
Comments
Log in or create a free account to join the discussion.