Go installation takes about five minutes on any computer, and it is the first step in our new Go programs series. In this post, you will install Go on Windows, macOS and Linux, check that it works, and run a small test program. After that, we will answer the most common interview questions about setup, with real programs and their output.
If you are new to the language, first read what Go is and why teams use it. We also have a short first program guide from the tutorial series. This post goes further, because it covers every operating system, the Go environment variables and the setup questions that interviewers like to ask.
What is Go Installation?
Go installation means putting the Go toolchain on your computer. The toolchain is one download that holds the compiler, the standard library and the go command. With it, you can build, run, test and format Go code.
Think of it like setting up a kitchen. The compiler is the stove, the standard library is the pantry, and the go command is the chef who uses both. Once the kitchen is ready, you can cook any recipe.
Why a Clean Go Installation Matters
A clean setup saves you hours later. Most Go installation errors, such as “go is not recognized”, come from a broken PATH and not from the code. So it is worth doing this step carefully once.
- Interviews: many Go interviews start with setup questions such as “What is GOPATH?” or “Where does go install put binaries?”.
- Team work: when everyone uses a supported Go version, builds behave the same on every laptop.
- Tools: editors like VS Code need a working
gocommand to give you autocomplete and error hints.
How Go Installation Works
Every Go installation follows the same four steps, whatever your operating system is. First, you download the right package from the official site. Next, you run the installer or extract the archive. Then, you make sure the go/bin folder is on your PATH. Finally, you open a new terminal and run go version.

The table below shows what the official installer puts on each system by default.
| System | Package type | Default folder | PATH added |
|---|---|---|---|
| Windows | .msi installer | C:\Program Files\Go | Yes, automatically |
| macOS | .pkg installer | /usr/local/go | Yes, automatically |
| Linux | .tar.gz archive | /usr/local/go | No, you add it |
Go Installation on Windows
Windows has the easiest setup, because the installer does almost everything for you.
- Open the official Go download page and pick the Windows .msi file for your system (usually amd64).
- Double-click the file and follow the steps. Keep the default folder unless you have a good reason to change it.
- Close every open Command Prompt or PowerShell window. Old windows still use the old PATH.
- Open a new terminal and run the version command shown below.
go version
You should see a line like this one. Your version number may be newer.
go version go1.27.2 windows/amd64
Install Go with winget
If you like the command line, Windows Package Manager can do the same job in one step.
winget install --id GoLang.Go
Go Installation on macOS
On a Mac, you can use the official .pkg file or Homebrew. Both work well, so pick one and stay with it.
Option 1: the official .pkg file
Download the macOS package from go.dev/dl. Choose ARM64 for Apple chips (M1 and later) and x86-64 for older Intel Macs. Then open the file and click through the installer. It puts Go in /usr/local/go and adds /usr/local/go/bin to your PATH.
Option 2: Homebrew
Homebrew is a popular package manager for macOS. If you already use it, this one command installs Go.
brew install go
go version
The output looks like this on an Apple chip Mac.
go version go1.27.2 darwin/arm64
Go Installation on Linux
A Linux Go installation means you extract an archive and set PATH yourself. It sounds harder, but it is only three commands. First, remove any old copy in /usr/local/go, because mixing two versions in one folder breaks Go.
# replace the file name with the version you downloaded
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.27.2.linux-amd64.tar.gz
# add Go to PATH for your user
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> ~/.profile
source ~/.profile
go version
Here is what each part does. The tar -C /usr/local part extracts Go into /usr/local/go. The export PATH line lets your shell find the go command. We also add $HOME/go/bin, so tools you install later work right away.
go version go1.27.2 linux/amd64
Why not apt install golang?
You can install Go with your distro’s package manager. However, these packages are often a few versions behind. For learning and for jobs, the official archive is the safer choice, because you always get the latest stable release.
Check Your Go Installation with go env
The go env command prints the settings the go command uses. It is the best tool to debug any Go installation problem. You can print all values, or just the ones you care about.
go env GOROOT GOPATH GOOS GOARCH GOBIN
On a Linux laptop, the output looks like this. GOBIN is empty, which is normal.
/usr/local/go
/home/asha/go
linux
amd64
The table below explains the most common Go environment variables.
| Variable | What it means | Default value |
|---|---|---|
| GOROOT | Where Go itself is installed | Install folder, like /usr/local/go |
| GOPATH | Your workspace for module cache and tools | $HOME/go |
| GOBIN | Where go install puts programs | Empty, so $GOPATH/bin is used |
| GOOS | Target operating system | Your current OS |
| GOARCH | Target CPU type | Your current CPU |
| GOPROXY | Where modules are downloaded from | proxy.golang.org |
To change a value for good, use go env -w. For example, go env -w GOBIN=$HOME/bin sets a new folder for installed tools. To undo it, run go env -u GOBIN.
Go Installation Test Program
Now let’s prove that everything works with a real program. Create a folder named hello-setup, then create the module and the file.
mkdir hello-setup
cd hello-setup
go mod init example.com/hello-setup
Step 1: A Tiny Go Installation Check
Put this code in a file named main.go. It is the smallest useful program, and it only prints two lines.
package main // every runnable Go program starts with package main
import "fmt" // fmt is the standard package for printing
// main is where the program starts
func main() {
fmt.Println("Hello, Go!")
// Go works out 2 + 3 first, then prints the answer
fmt.Println("2 + 3 =", 2+3)
}
Run it with this command from inside the folder.
go run .
You should see these two lines.
Hello, Go!
2 + 3 = 5
The go run . command compiles every file in the folder and runs it. fmt.Println prints its values with a space between them. If you see both lines, the compiler and the go command both work.
Step 2: Print Facts About Your Go Installation
Now replace the code in main.go with this version. It prints a greeting and some facts about your setup.
package main
// We import two packages, so we put them inside ( )
import (
"fmt"
"runtime" // runtime gives facts about the running program
)
// main prints a greeting and four facts about this computer
func main() {
fmt.Println("Hello, Go! Your setup works.")
fmt.Println("Go version:", runtime.Version()) // the Go release that built this program
fmt.Println("OS:", runtime.GOOS) // operating system, like linux or windows
fmt.Println("CPU type:", runtime.GOARCH) // CPU family, like amd64 or arm64
fmt.Println("CPU cores:", runtime.NumCPU()) // how many CPU cores Go can see
}
Run it again with go run . from the same folder.
Here is the output on a Linux laptop with 8 cores. Your values will match your own machine.
Hello, Go! Your setup works.
Go version: go1.27.2
OS: linux
CPU type: amd64
CPU cores: 8
In short, package main and func main() mark this file as a program. The runtime package tells us which Go version built it and where it runs. If you see this output, your Go installation is complete.
Set Up VS Code for Go
You can write Go in any editor once your Go installation works. Still, most beginners use VS Code, because the free Go extension is very good.
- Install VS Code from its official site.
- Open the Extensions panel and install the extension named “Go” by the Go team at Google.
- Open your
hello-setupfolder. When VS Code asks to install Go tools such as gopls, click Install All. - Save
main.go. The extension formats it and shows errors as you type.
Go Installation vs Online Compiler
Some beginners skip setup and use a browser tool instead. The comparison below shows when each one makes sense.

| Feature | Local Go installation | Online Go compiler |
|---|---|---|
| Setup time | About five minutes | None |
| Works offline | Yes | No |
| File and network access | Full access | Blocked or limited |
| Third-party packages | Any package | Limited |
| Real projects | Yes | Not practical |
| Sharing a snippet | Needs Git or a gist | One share link |
So, install Go locally for real learning and projects. Use an online tool when you want to test a tiny idea or share code with a friend. We list the best online options in a later post of this series.
Common Go Installation Mistakes
- Old terminal window: the PATH change only applies to new windows. Close and reopen your terminal after you install Go.
- Two Go versions in one folder: on Linux, always delete /usr/local/go before you extract a new archive.
- Wrong CPU file: an ARM Mac needs the arm64 file, and most Windows PCs need amd64.
- Setting GOROOT by hand: modern Go finds GOROOT by itself. A wrong manual value causes strange errors.
- Code inside GOROOT: never save your projects in the Go install folder. Use any normal folder with
go mod init.
Best Practices After Go Installation
- Use the latest stable version. The Go team supports only the two newest releases with security fixes.
- Run go version and go env first whenever something breaks, because they show the real setup.
- Add $HOME/go/bin to PATH, so tools you install with
go installrun from anywhere. - Use modules for every project, so you can keep code in any folder you like.
- Update the same way you installed. If you used Homebrew, update with
brew upgrade go.
Go Installation Interview Questions and Answers
These Go installation questions come up often in interviews. Many answers include a small program, so you can run it and see the output yourself.
Go Installation Basics Questions
Q1. How do you check which Go version is installed?
Run go version in a terminal. It prints the version, the OS and the CPU type, for example go version go1.27.2 linux/amd64. Inside a program, you can call runtime.Version().
Q2. What is GOROOT?
GOROOT is the folder where Go itself lives, such as /usr/local/go. It holds the compiler and the standard library source. You almost never need to set it, because the go command finds it on its own.
Q3. What is GOPATH, and is it still needed?
GOPATH is your Go workspace, by default $HOME/go. Before modules, all code had to live inside it. Today, modules let you work in any folder. Still, GOPATH holds the module cache in pkg/mod and installed tools in bin.
Q4. What is the difference between GOROOT and GOPATH?
GOROOT holds Go’s own files, and GOPATH holds your downloaded modules and tools. In short, GOROOT belongs to Go, while GOPATH belongs to you.
Go Environment Variable Questions
Q5. Why does this program print an empty GOPATH?
package main
import (
"fmt"
"os"
)
// main reads the GOPATH variable straight from the system
func main() {
// os.Getenv returns "" when the variable is not set
gopath := os.Getenv("GOPATH")
// %q prints the text inside double quotes, so an empty value shows as ""
fmt.Printf("GOPATH = %q\n", gopath)
}
GOPATH = ""
The program reads the real environment variable, and most people never set it. The go command uses a default of $HOME/go when it is missing. So go env GOPATH shows a path, but os.Getenv shows an empty string.
Q6. Where does go install put the binary?
It puts it in GOBIN if that is set. Otherwise, it uses $GOPATH/bin, which is usually $HOME/go/bin. That is why you add this folder to PATH.
Q7. You get “go: command not found” or “‘go’ is not recognized”. What do you check?
First, open a new terminal, because old windows keep the old PATH. Then check that the Go bin folder, such as /usr/local/go/bin, is on PATH. On Windows, run where go, and on macOS or Linux, run which go.
Q8. What does go env -w do?
It saves a Go setting in your user config file, so it stays after you close the terminal. For example, go env -w GOPROXY=https://proxy.golang.org,direct. You can remove it again with go env -u GOPROXY.
Q9. How do you print the OS and CPU type from a program?
Use the runtime package. The values are fixed when the program is built.
package main
import (
"fmt"
"runtime"
)
// main prints the system this program was built for
func main() {
system := runtime.GOOS // operating system, like linux
cpu := runtime.GOARCH // CPU type, like amd64
// + joins strings together
fmt.Println(system + "/" + cpu)
}
linux/amd64
runtime.GOOS and runtime.GOARCH are plain strings. The program joins them with a slash and prints the result.
Q10. What are GOOS and GOARCH used for?
They choose the target system for a build. For example, GOOS=windows GOARCH=amd64 go build makes a Windows .exe on a Linux machine. Our Go cross compilation guide covers this in detail.
Go Version and Toolchain Questions
Q11. How can you keep two Go versions on one machine?
Install the extra version as a separate command. For example, run go install golang.org/dl/go1.26.0@latest, then go1.26.0 download. After that, go1.26.0 version uses the old release, and go still uses your main one.
Q12. What is GOTOOLCHAIN?
It controls which Go toolchain runs your build. If a module’s go.mod says it needs a newer Go, the go command can download that toolchain for you. Setting GOTOOLCHAIN=local turns this off and always uses the installed version.
Q13. How do you update Go?
Use the same method you used to install it. On Windows and macOS, run the new installer. On Linux, delete /usr/local/go and extract the new archive. With Homebrew, run brew upgrade go.
Q14. How do you uninstall Go?
Delete the Go install folder and remove it from PATH. On Windows, use “Add or remove programs”. You can also delete $HOME/go if you no longer need the module cache and tools.
Program Output Questions
Q15. What does this program print, and why?
package main
import "fmt"
// main prints a word and the result of a comparison
func main() {
// 1+1 == 2 asks a yes or no question, so its value is true or false
fmt.Println("Go", 1+1 == 2)
}
Go true
Println puts a space between values and adds a new line at the end. The expression 1+1 == 2 is a bool, so it prints true. Interviewers use tiny programs like this to check basic output rules.
Q16. Why must every program have package main and func main?
The go command only builds a runnable program from package main. Inside it, func main() is the entry point where the program starts. Without both, you get a library package and not a program.
Q17. What happens if you name the package something else?
go run fails with an error. For example, with package hello, Go says the package is not a main package. The fix is to change it back to package main.
Q18. How many CPU cores can a Go program use by default?
By default, Go can use all logical cores, and runtime.NumCPU() reports how many there are. You can limit it with the GOMAXPROCS environment variable. This matters later when we cover goroutines.
Module and Proxy Questions
Q19. What is GOPROXY, and why does it matter?
GOPROXY is the server that go uses to download modules. The default is proxy.golang.org, which is fast and caches public modules. Companies often set their own proxy for private code.
Q20. Do you need to set GO111MODULE today?
No. Module mode has been the default for years, so you can leave GO111MODULE unset. You only see it in very old tutorials.
Q21. Where is the module cache stored?
It lives in $GOPATH/pkg/mod. You can print the exact folder with go env GOMODCACHE, and clear it with go clean -modcache.
Q22. How do you verify the download is safe?
The download page lists a SHA256 checksum for each file. You can compare it with sha256sum on Linux or shasum -a 256 on macOS. Installers from go.dev are also signed.
Practice Task
Install Go on your machine, then change the test program so it also prints the number of goroutines with runtime.NumGoroutine(). Hint: a plain program starts with exactly one goroutine, the one running main.
Official Resources
- Download and install Go (official guide)
- All Go downloads
- Managing Go installations
- runtime package documentation
Quick Recap
- Go installation puts the compiler, standard library and the
gocommand on your computer. - Windows and macOS installers set PATH for you, but on Linux you add /usr/local/go/bin yourself.
go versionandgo envare the first commands to run when something breaks.- GOROOT is where Go lives, and GOPATH holds your module cache and tools.
- A small program with the
runtimepackage proves the setup works.
What’s Next?
Your setup is ready, so next we learn every way to run code. Read how to run a Go program with go run, go build and go install. When you want more setup practice for interviews, try the Go basics interview questions.


