IntelliJ IDEA
 
Get IntelliJ IDEA
You are viewing the documentation for an earlier version of IntelliJ IDEA.

GOROOT and GOPATH

Last modified: 10 August 2022

To see settings for GOROOT and GOPATH, open settings by pressing Ctrl+Alt+S and expand the Go node

Download the Go SDK right from the IDE

Configure GOPATH for different scopes

Go tools expect a certain layout of the source code. GOROOT and GOPATH are environment variables that define this layout.

GOROOT is a variable that defines where your Go SDK is located. You do not need to change this variable, unless you plan to use different Go versions.

GOPATH is a variable that defines the root of your workspace. By default, the workspace directory is a directory that is named go within your user home directory (~/go for Linux and MacOS, %USERPROFILE%/go for Windows). GOPATH stores your code base and all the files that are necessary for your development. You can use another directory as your workspace by configuring GOPATH for different scopes. GOPATH is the root of your workspace and contains the following folders:

  • src/: location of Go source code (for example, .go, .c, .g, .s).

  • pkg/: location of compiled package code (for example, .a).

  • bin/: location of compiled executable programs built by Go.

Consider the following animation where we change the Go SDK from 1.16.1 to 1.16.3 and assign the project GOPATH to the newly-downloaded SDK directory.

https://resources.jetbrains.com/help/img/idea/2022.1/go_changing_goroot_and_gopath.png
Gif