Lesson 2 of 60 · Go
Installing Go & Setting Up the Workspace
Duration: 15 minutes
Installing Go & Setting Up the Workspace
This lesson explains how to install Go on Windows, macOS, and Linux, then create a simple module and understand the basic workspace structure.
Install Go
Windows
- Go to https://go.dev/dl/ and download the Windows MSI installer.
- Run the installer and accept the default installation location.
- Open PowerShell and verify the installation:
go version
- Check that Go is on your PATH and that the install location is correct:
go env GOROOT
go env GOPATH
go env GO111MODULE
If go version does not work, open Windows Settings, search for Environment Variables, and add C:\Go\bin to the PATH. Then restart PowerShell.
macOS
- Download the macOS package from https://go.dev/dl/ and run the installer.
- Open Terminal and verify:
go version
- If the command is not found, add Go to your shell PATH:
export PATH="$PATH:/usr/local/go/bin"
Then restart your terminal or source your shell profile.
Linux
- Download the Linux tarball from https://go.dev/dl/.
- Extract it to
/usr/local:
sudo tar -C /usr/local -xzf go1.22.linux-amd64.tar.gz
- Add Go to your PATH:
export PATH="$PATH:/usr/local/go/bin"
- Verify the installation:
go version
Modules and Workspace Basics
Go uses modules to manage dependencies and versions. A module is a collection of packages with a go.mod file at its root. Modules allow your code to live anywhere on disk, not just inside GOPATH.
Create a new project directory and initialize a module:
mkdir hello-go
cd hello-go
go mod init github.com/yourname/hello-go
Create main.go:
package main
import "fmt"
func main() {
fmt.Println("Hello from your first Go module!")
}
Run the project:
go run main.go
Build a reusable binary:
go build
This produces an executable named hello-go on macOS/Linux or hello-go.exe on Windows. Use go env to inspect your Go configuration and verify your module is active.