Complete Go Starter Guide: Setup, Syntax & First Program
Source: Dev.to
Introduction
Have you ever felt like you want to code and learn a new programming language, but there are so many languages to choose from: Java, Python, Rust, Go? I researched, and Go caught my interest, as highlighted by the JetBrains report here. Go was used by approximately 4.8 million users. Many companies have widely accepted Go for backend development and libraries due to its high performance.
There are many advantages of Go, which we will cover in future articles. A bit of background on Go:
- Created at Google; first public release in 2009.
- Designed to address large‑scale system issues at Google (slow compilation, complexity, poor concurrency support).
- Intended to be simple, developer‑friendly, and readable—more approachable than C++ or Java, yet retaining many of their strengths.
By the end of this article we will have Go installed and will have written our first program.
Installation & Verification
Step 1 – Download & Install
- Visit the official download page: .
- Grab the installer for your operating system and run it.
- The installer sets up Go and configures the necessary paths.
Tip: On macOS you can also install via Homebrew: brew install go.
Step 2 – Verify Installation
Open a terminal (bash, PowerShell, etc.) and run:
go version
# Example output:
# go version go1.25.5 darwin/arm64
If you see something like go version go1.21.5 … the installation succeeded and Go is ready to use.
What Are Go Modules?
A Go module is a collection of Go files that includes a go.mod file. The go.mod file tracks the module’s name and its dependencies. In the past this was handled via a special workspace (GOPATH), but modules have replaced that approach.
Create a New Module
mkdir my-go-app
cd my-go-app
# Replace <module-name> with a name you like (e.g., a repository URL)
go mod init my-first-go-project
The command creates a go.mod file, which becomes the root of your Go project. All subsequent commands run relative to this folder.


Nostalgic “Hello, World!”
Inside the project folder create a file named main.go and add the following code:
package main // Every executable program starts with package main
import "fmt"
// Unlike Python, where functions like print are built‑in,
// in Go they live in packages; we need fmt for printing.
func main() { // Entry point of the program
fmt.Println("Hello, World!") // Prints the text
}
Running & Building: go run vs go build
go run — Quick Testing
Why use it? To instantly check whether your code works; no binary is left behind.
go run main.go

go build — Create an Executable
Why use it? To compile a standalone binary that can be shared or run later, even on machines without Go installed.
go build main.go # Produces an executable (e.g., main.exe on Windows)
After running the command you’ll see a binary file in the folder (main on macOS/Linux, main.exe on Windows). You can execute it directly.
Current Project Layout
Run the following to view the directory structure (use dir on Windows):
ls -la
# Output:
# my-go-app/
# ├── go.mod # Module definition
# ├── main.go # Source code
# └── main # Compiled binary (or main.exe on Windows)
Variables and Basic Types
Variables are containers for storing data. Go is statically typed, so each variable’s type must be known at compile time.
Basic Types
| Type | Description |
|---|---|
string | Text (e.g., "Hello") |
int | Whole numbers (e.g., 10, -10) |
float64 | Decimal numbers (e.g., 3.14) |
bool | Boolean (true or false) |
Three Ways to Declare Variables
1. Full Declaration (Verbose)
var name string = "Tom Cruise"
var age int
age = 25
2. Type Inference (Shorter)
var name = "Tom Cruise" // Go infers `string`
var age = 25 // Go infers `int`
3. Short Variable Declaration (Inside Functions)
func main() {
name := "Tom Cruise" // := declares & infers type
age := 25
fmt.Println(name, age)
}
Variable Declarations in Go
Below are the different ways you can declare variables in Go, along with short examples.
1. Full Declaration (Outside Functions)
package main
import "fmt"
var name string = "Tom" // Full declaration with type
var age = 30 // Type inference – Go infers `int`
func main() {
fmt.Println(name, age)
}
2. Short Declaration (Mostly Inside Functions)
Use the := operator. It declares and initializes the variable in a single step.
package main
import "fmt"
func main() {
name := "Tom" // string
age := 25 // int
isActor := true // bool
height := 5.5 // float64
fmt.Println(name, age, isActor, height)
}
3. Putting It All Together
A sample main.go that combines the different declaration styles:
package main
import "fmt"
func main() {
var name string = "Tom" // Full declaration
var age = 25 // Type inference
isActor := true // Short declaration (inside main)
height := 5.5 // Float64
fmt.Println(name, age, isActor, height) // using variables
age = 26 // changing variable
fmt.Println(name, age, isActor, height) // using variables again
}
What’s Next?
We have:
- Installed Go
- Created a module‑based project
- Ran our first program
- Learned basic data types and variable declarations
Try It Yourself
- Change the message in the
fmt.Printlnstatement. - Create new variables and store different values in them.
- Attempt to assign a string to an
intvariable and note the compiler error. - Build an executable with
go buildand share it with a friend.
In upcoming articles we’ll cover more syntax, including conditionals and loops.
Need help? Drop a comment with your output or any questions, and I’ll do my best to answer them.