Go Installation and Setup

Before writing any Go code, the Go compiler must be installed on the machine. The compiler reads the code and turns it into a program the computer can run. This topic covers the full setup process for Windows, macOS, and Linux.

What Needs to Be Installed

Only two things are needed to start writing Go programs:

  • Go Compiler – the official Go toolchain from the Go website
  • Code Editor – a tool to write and manage code files

Step 1 – Download Go

Visit the official Go website at https://go.dev/dl/ and download the installer for the operating system in use.

Operating SystemFile to Download
Windows.msi installer file
macOS.pkg installer file
Linux.tar.gz archive file

Step 2 – Install Go

Windows

Run the downloaded .msi file and follow the on-screen instructions. The installer automatically sets up Go and adds it to the system path.

macOS

Open the downloaded .pkg file and follow the installation steps. Go installs to /usr/local/go by default.

Linux

Open the terminal and run the following commands one by one:

# Remove any old Go installation
sudo rm -rf /usr/local/go

# Extract the downloaded archive (replace version as needed)
sudo tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz

# Add Go to PATH – paste this line into ~/.profile or ~/.bashrc
export PATH=$PATH:/usr/local/go/bin

# Apply the changes
source ~/.profile

Step 3 – Verify Installation

Open a terminal or command prompt and type:

go version

The output should look like this:

go version go1.22.0 linux/amd64

This confirms Go installed correctly and the version number shows which release is active.

Step 4 – Choose a Code Editor

Any plain text editor works for Go, but a proper code editor makes writing and debugging much easier. The most popular choice is Visual Studio Code (VS Code).

Setting Up VS Code for Go

  1. Download VS Code from https://code.visualstudio.com
  2. Open VS Code and press Ctrl+Shift+X to open Extensions
  3. Search for Go and install the extension by Google
  4. Open any .go file – VS Code will prompt to install Go tools automatically

The Go extension adds features like auto-complete, error highlighting, and code formatting.

Understanding the Go Workspace

Go uses a module-based system to organize projects. Each project lives in its own folder and has a special file called go.mod that tracks the project name and dependencies.

Creating the First Project Folder

# Create a new folder for the project
mkdir myfirstapp
cd myfirstapp

# Initialize a Go module
go mod init myfirstapp

After running these commands, Go creates a go.mod file inside the folder. This file marks the folder as an official Go project.

Folder Structure Diagram

myfirstapp/
├── go.mod          ← project name and Go version
└── main.go         ← the main code file

Useful Go Commands

CommandWhat It Does
go versionShows the installed Go version
go run filename.goCompiles and runs a Go file directly
go buildCompiles the project into an executable file
go fmt filename.goAutomatically formats the code to Go standards
go mod init nameCreates a new Go module in the current folder

Key Points

  • Go is downloaded from the official site at go.dev/dl
  • Run go version to confirm successful installation
  • VS Code with the Go extension is the recommended editor
  • Every Go project starts with go mod init to create a module
  • go run compiles and runs code in one step — great for learning

Leave a Comment