Tutorials Logic, IN info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Website Development
Practice
Quiz Challenge Interview Questions Certification Practice
Tools
Online Compiler JSON Formatter Regex Tester CSS Unit Converter Color Picker
Compiler Tools

Golang Setup: Install Golang, Run Programs and Configure Workspace

Install Golang

Install Golang from the official distribution for your operating system. After installation, the go command becomes the center of your workflow. The same command is used for running, building, testing, formatting, documentation, modules, and dependency management.

A beginner-friendly setup is Golang, VS Code or GoLand, the Golang editor extension, and a terminal. You do not need a large framework to begin because the standard library already includes packages for files, HTTP, JSON, testing, command-line flags, strings, time, and more.

After installing, close and reopen your terminal so the updated PATH is loaded. If go version does not work, the most common issue is that the Golang binary directory was not added to PATH.

Verify Installation
go version
go env GOPATH
go env GOMOD

Understand GOPATH and Modules

Older Golang projects often depended heavily on GOPATH. Modern Golang development uses modules. A module is a versioned collection of packages defined by a go.mod file.

When go env GOMOD prints a path to go.mod, you are inside a module. When it prints nothing or /dev/null depending on the environment, you are outside a module. For new projects, create a module first.

TermMeaning
GOPATHWorkspace location used by older workflows and module cache defaults.
GOMODPath to the active go.mod file.
go.modModule name, Golang version, and dependency requirements.
go.sumDependency checksums for repeatable builds.

Create Your First Module

Create a new folder, initialize a module, add a main.go file, and run it. The command go run . compiles and executes the current module in one step, which is convenient while learning.

The module path can be a repository-style path such as github.com/company/project. For local practice, an example path is fine. The path becomes important when other modules import your packages.

Create and Run a Module
mkdir hello-golang
cd hello-golang
go mod init example.com/hello-golang
go run .

Write main.go

An executable Golang program uses package main and a function named main. This function is the entry point of the compiled program.

Save this file as main.go inside the module folder. Then run go run .. If the program prints the message, your setup is working.

First Program
package main

import "fmt"

func main() {
    fmt.Println("Golang setup is ready")
}

Build, Format and Test

Golang ships with a complete command-line workflow. You should learn the core commands early because they appear in almost every real project.

go build compiles a binary, gofmt standardizes formatting, and go test runs tests. These tools make Golang projects consistent even across large teams.

CommandPurpose
go run .Compile and run the current module.
go buildCreate a binary executable.
gofmt -w .Format Golang files in place.
go test ./...Run all tests in the module.
go doc fmt.PrintlnRead documentation from the terminal.
go mod tidyClean missing and unused dependency requirements.

Recommended Editor Setup

Use an editor that can format on save, show type errors, run tests, and navigate to definitions. VS Code with the official Golang extension is a common choice, while GoLand provides a full IDE experience.

Turn on format on save. Golang teams expect formatted code, and gofmt removes style debates from the workflow. If your editor reports missing tools, allow it to install the recommended Golang tools.

  • Enable format on save so gofmt runs automatically.
  • Use editor diagnostics to catch compile errors early.
  • Run small programs with go run . while learning.
  • Use go test ./... before committing changes.
  • Keep each practice project inside its own module folder.
Key Takeaways
  • The go command handles running, building, testing, formatting, docs, and modules.
  • Modern Golang projects should use modules and a go.mod file.
  • Executable programs use package main and func main().
  • Use gofmt or format on save to keep code consistent.
  • Run go test ./... regularly as projects grow.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.