GOROOT and GOPATH
To view settings for GOROOT and GOPATH, press CtrlAlt0S to open settings, then expand the Go node.
Download the Go SDK directly 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.
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
bygo install
, with$GOBIN
defaulting to$GOPATH/bin
.Modules are cached in
$GOMODCACHE
bygo get
, defaulting to $GOPATH/pkg ./mod Checksum database state is cached in $GOPATH
/pkg by/sumdb go get
.
For details about the GOPATH variable, refer to the go command documentation.
note
The concept of GOPATH development mode, which precedes Go modules, is now deprecated. Prior to Go modules, the GOPATH was used to install binaries and compiled packages, as well as downloading source code to specified paths. For more information about developing with GOPATH, refer to GOPATH development mode at go.dev.
Consider the following video where we change the Go SDK to a newer version.
To see the current value of GOROOT, open settings (CtrlAlt0S) and navigate to Go GOROOT. Click the drop-down list and select the Go version.
If no Go version is available, click the Add SDK button to download a Go version or select a path to a local copy of Go SDK.
Ensure that the provided path to the folder with Go SDK includes bin and src folders.
Open settings (CtrlAlt0S) and navigate to Go GOROOT.
Click the Add SDK button
and select Local.
In the file browser, navigate to the SDK version that is on your hard drive.
Click Open.
Open settings (CtrlAlt0S) and navigate to Go GOROOT.
Click the Add SDK button (
) and select Download.
From the Version list, select the SDK version.
In the Location field, specify the path for the SDK. To use a file browser, click the Browse icon
.
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.
note
To use asdf as a Go SDK management tool, ensure that you installed asdf and the necessary Go versions.
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
).
Open settings by pressing CtrlAlt0S and navigate to Go | GOROOT.
From the list, select the Go version that you need.
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.
note
If you configure all three scopes, GoLand uses the narrowest scope.
Open settings by pressing CtrlAlt0S and navigate to Go | GOPATH.
Select the scope you want to configure:
Global GOPATH
Project GOPATH
Module GOPATH
Click Add
.
In the file browser, select the directory you want to associate with GOPATH.