Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

What Are GOROOT, GOPATH and GOBIN in Go?

Go
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedNov 19, 2026
5 min read

GOROOT is the directory where the Go toolchain is installed, GOPATH is the workspace directory where Go stores downloaded modules and installed tools (by default ~/go), and GOBIN is the optional folder where go install puts executables. Knowing GOPATH vs GOROOT saves time when a command is not found or a cache grows large.

Since Go modules became the default, you rarely edit any of these three variables. This guide explains what each one means, how to read it, and when changing it makes sense.

Table of Contents

  • Read the values with go env
  • What GOROOT is
  • What GOPATH is and what lives in it
  • What GOBIN is
  • How GOROOT, GOPATH and GOBIN differ
  • Modules replaced the old GOPATH workflow
  • Setting a variable on each system
  • Frequently Asked Questions
    • Do I need to set GOPATH after installing Go?
    • Why does the module cache take so much disk space?
    • Can my project live outside GOPATH?
    • Where do tools installed with go install end up?
  • Summary
  • Related Articles

Read the values with go env

The go env command prints the settings the toolchain actually uses, which is more reliable than checking your shell variables.

bash
text

The empty line is GOBIN: when it is unset, go install falls back to GOPATH/bin. To change a value permanently without editing shell files, use go env -w GOBIN=/home/you/bin, which writes to a per-user config file. Use go env -u GOBIN to remove the setting again.

What GOROOT is

GOROOT points to the Go distribution itself: the compiler, linker, go command and the standard library source.

text

The go binary finds its own GOROOT from its location, so you should not set it yourself. Setting it wrongly is a classic cause of errors such as "cannot find package fmt". Only change it if you intentionally keep a toolchain in an unusual location.

What GOPATH is and what lives in it

GOPATH defaults to $HOME/go (%USERPROFILE%\go on Windows). Before Go 1.11 all your code had to live in GOPATH/src. With modules, your projects can sit in any folder, and GOPATH is mainly a store:

PathContents
GOPATH/pkg/modThe module cache: every dependency version you downloaded, read-only
GOPATH/binExecutables installed with go install (when GOBIN is not set)
GOPATH/srcOnly used by very old, pre-module projects

You can list and clear the module cache with Go itself:

bash

go clean -modcache deletes all downloaded modules; the next build downloads what it needs again. The build cache (compiled packages) is separate and found with go env GOCACHE.

What GOBIN is

GOBIN is the directory go install writes executables to. If it is empty, Go uses GOPATH/bin. Whichever folder applies must be on your PATH, otherwise the installed tool cannot be started by name.

bash
text

On Linux and macOS add the line export PATH=$PATH:$(go env GOPATH)/bin to your shell profile. On Windows add the same folder through the system environment variables dialog.

How GOROOT, GOPATH and GOBIN differ

VariableAnswers the questionDefaultShould you change it?
GOROOTWhere is Go installed?Install folder, for example /usr/local/goAlmost never
GOPATHWhere do modules and tools go?~/goRarely, for example to use another disk
GOBINWhere do installed commands go?GOPATH/binSometimes, to share one tools folder

A simple rule: GOROOT is Go, GOPATH is your downloads, and GOBIN is your commands.

Modules replaced the old GOPATH workflow

In the old workflow each project had to be inside GOPATH/src/github.com/you/project, and dependencies were fetched into that tree with go get. Today a project has a go.mod file and can be in any folder. The old mode is switched off by default, and the GO111MODULE variable is no longer something a beginner needs. If you find tutorials that tell you to put code in GOPATH/src, treat them as outdated and use go mod init instead.

Setting a variable on each system

To make your own values permanent, prefer the Go tool. It stores them in a small per-user file, so they apply in every terminal and in editors such as VS Code.

bash
text

A value set in a real environment variable takes priority over the file. If go env shows something unexpected, check whether your shell profile exports the same name. Remember to add the chosen bin folder to PATH afterwards.

Frequently Asked Questions

Do I need to set GOPATH after installing Go?

No. It has a working default, ~/go. Set it only if you want the module cache and tools on a different drive.

Why does the module cache take so much disk space?

It keeps every version of every dependency you ever built. Run go clean -modcache to reclaim space; Go downloads modules again when needed.

Can my project live outside GOPATH?

Yes. With modules, a folder with a go.mod can be anywhere on disk.

Where do tools installed with go install end up?

In GOBIN if set, otherwise in GOPATH/bin. Check go env GOBIN GOPATH and make sure that folder is on PATH.

Summary

GOROOT is the toolchain installation and normally needs no setting. GOPATH is the default ~/go store for the module cache and installed tools, and GOBIN overrides where go install places commands. Inspect all of them with go env and put the resulting bin folder on your PATH.

Related Articles

  • How Do You Set Up VS Code for Go Development?
  • Go Short vs Long Variable Declarations: := and var Explained
  • Learn Go: Complete Study Roadmap from Beginner to Advanced
Share