Tutorials Logic, IN info@tutorialslogic.com

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

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.

Term Meaning
GOPATH Workspace location used by older workflows and module cache defaults.
GOMOD Path to the active go.mod file.
go.mod Module name, Golang version, and dependency requirements.
go.sum Dependency 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

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

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.

Command Purpose
go run . Compile and run the current module.
go build Create a binary executable.
gofmt -w . Format Golang files in place.
go test ./... Run all tests in the module.
go doc fmt.Println Read documentation from the terminal.
go mod tidy Clean 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.
Before you move on

Golang Setup: Install Golang, Run Programs and Configure Workspace Mastery Check

5 checks
  • Older Golang projects often depended heavily on GOPATH.
  • 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.

Go Setup Boundary

  • Wrong toolchain on PATH

    When go version differs from the installed release, inspect command resolution before reinstalling. Multiple Go installations commonly leave an older binary earlier on PATH.
Next Step
Next Practice

Finish the concept here, then reinforce it with hands-on coding, interview prep, or a tool that matches the topic.

Browse Free Tutorials

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