GoLand 2025.1 Help

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.

In Go development, the GOPATH variable, which defaults to $HOME/go on Unix and %USERPROFILE%\go on Windows, serves several purposes:

  • Binaries are installed to $GOBIN by go install, with $GOBIN defaulting to $GOPATH/bin.

  • Modules are cached in $GOMODCACHE by go get, defaulting to $GOPATH/pkg/mod.

  • Checksum database state is cached in $GOPATH/pkg/sumdb by go get.

For details about the GOPATH variable, refer to the go command documentation.

Consider the following video where we change the Go SDK to a newer version.

GOROOT

Configure GOROOT

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

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

  2. Click the Add SDK button the Add SDK button and select Local.

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

  4. Click Open.

    Select 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 button (the Add SDK icon) and select Download.

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

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

  5. Click OK to close the Download Go SDK dialog.

    As you click Apply or OK on the GOROOT page, GoLand will start downloading and unpacking the Go SDK.

    Download the Go SDK

Using asdf

asdf is a tool that manages multiple versions of different programming languages and utilities. It allows switching between different Go versions for different projects. Also, asdf can set different scopes: asdf global, which sets a default version for the entire system, and asdf local, which sets a version for a specific directory.

GoLand supports asdf local and asdf global commands, including specifying multiple versions (for example, asdf local golang 1.21.0 1.20.8).

Select an asdf Go version for the project

  1. Open settings by pressing Ctrl+Alt+S and navigate to Go | GOROOT.

  2. From the list, select the Go version that you need.

    Select an asdf Go version for the project

GOPATH

Configuring GOPATH for different scopes

You can configure GOPATH for the following scopes:

  • Global GOPATH: applies to all projects in the current installation of GoLand.

  • Project GOPATH: applies only to the current project.

  • Module GOPATH: applies only to a specific module. A module can use a different SDK than the one configured for the project. It can also include a specific technology or framework.

  1. Open settings by pressing Ctrl+Alt+S and navigate to Go | GOPATH.

  2. Select the scope you want to configure:

    • Global GOPATH

    • Project GOPATH

    • Module GOPATH

  3. Click Add the Add button.

  4. In the file browser, select the directory you want to associate with GOPATH.

    Configuring GOPATH for different scopes
Last modified: 04 April 2025