GoLand 2019.2 Help

Configuring GOROOT and GOPATH

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. Under GOPATH, you can store your code base and all the files that are necessary for your development. The go get tool downloads packages to the first workplace that is specified in GOPATH. If GOPATH is not set, the default values are ~/go (Linux and MacOS) and %USERPROFILE%/go on Windows. GOPATH is the root of your workspace and contains the following folders:

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

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

  • bin/: location of executables built by Go.

GOROOT

Configuring GOROOT

To see the current value of GOROOT, open settings (Ctrl+Alt+S) and navigate to Go | GOROOT. Click the drop-down list and select the Go version.

If no Go version is available, download a Go version or specify a path to a local copy of Go SDK.

Configuring GOROOT

Ensure that the provided path to the folder with Go SDK includes bin и src folders.

  1. Open settings (Ctrl+Alt+S) and navigate to Go | GOROOT.

  2. Click the Add SDK icon the Add SDK icon near the GOROOT field and select Local.

  3. In the file browser, navigate to the SDK version that is on your hard drive.

  4. Click Open.

Navigate to a local copy of Go SDK

Download the Go SDK

  1. Open settings (Ctrl+Alt+S) and navigate to Go | GOROOT.

  2. Click the Add SDK icon (the Add SDK icon) near the GOROOT field and select Download.

  3. From the Version list, select the SDK version.

  4. In the Target directory field, specify the path for the SDK. To use a file browser, click the Browse icon the Browse icon.

  5. Click OK.

Download the Go SDK

GOPATH

Configuring GOPATH for different scopes

You can configure GOPATH for the following scopes: Global, Project, and Module. If you specified all three scopes, GoLand selects the most specific scope first.

  1. Open settings (Ctrl+Alt+S) and navigate to Go | GOPATH.

  2. Depending on the scope that you want to apply, select the corresponding section (Global GOPATH, Project GOPATH, Module GOPATH) and click the Add button the Add button.

  3. Navigate to the directory that you want to associate with GOPATH.

  4. Click OK.

Configuring GOPATH for different scopes
Last modified: 29 October 2019