# GOROOT and GOPATH

> **TL;DR**
> To configure your Go environment, open settings (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) and expand the Go node.
>
>
>
> You can [download the Go SDK](#download-go-sdk) directly from the IDE and configure GOROOT and GOPATH for your project.
>
>
>
> Use separate GOPATH configurations for different scopes if needed.

Go tools expect a specific structure for your source code. This structure is defined by two environment variables: GOROOT and GOPATH. Understanding and properly configuring these variables ensures your Go projects compile and run correctly.

The GOROOT variable specifies the location of your Go SDK. Usually, IntelliJ IDEA sets it automatically, so you don’t need to change it unless you want to use a different Go version.

The GOPATH variable defines the workspace for your Go projects. By default, its location is `$HOME/go` on Unix-like systems and `%USERPROFILE%\go` on Windows. It serves as the root directory for installed binaries, cached modules, and checksum data.

* Binaries are installed to `$GOBIN` by `go install` (default: `$GOPATH/bin`).

* Modules are cached in `$GOMODCACHE` by `go get` (default: `$GOPATH/pkg/mod`).

* Checksum database state is stored in `$GOPATH/pkg/sumdb`.

For more details, see the [GOPATH section of the go command documentation](https://pkg.go.dev/cmd/go#hdr-GOPATH_environment_variable).

> **Note:**
> The traditional GOPATH development mode, which predates Go modules, is now deprecated. Previously, GOPATH defined where binaries, compiled packages, and source files were stored. For more information, refer to [GOPATH development mode at go.dev](https://go.dev/wiki/GOPATH#gopath-development-mode).

The following video demonstrates how to change the Go SDK to a newer version in IntelliJ IDEA.

## GOROOT

The GOROOT setting defines which Go SDK version IntelliJ IDEA uses for your project. You can either download a new version directly from the IDE or configure a local installation.

Procedure: Configure GOROOT

* Open settings (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) and navigate to `Languages & Frameworks | Go GOROOT`.

Select a Go version from the list. If none is available, click Add SDK to either [download a Go version](#download-go-sdk) or [select a local Go SDK installation](#navigate-to-go-sdk).

Procedure: Select a local Go SDK

Ensure the selected folder includes both `bin` and `src` directories.

1. Open settings (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) and go to `Languages & Frameworks | Go GOROOT`.

2. Click the Add SDK button (![the Add SDK button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)), then select Local.

3. In the file browser, navigate to the Go SDK folder on your system.

4. Click Open to confirm.

![Select a local copy of Go SDK](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_ij_select_go_version.png)

Procedure: Download the Go SDK

1. Open settings (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) and navigate to `Languages & Frameworks | Go GOROOT`.

2. Click the Add SDK button (![the Add SDK icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) and select Download.

3. From the list, select the desired Go SDK version.

4. In the Location field, specify where to install the SDK. To browse for a location, click the Browse icon (![the Browse icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.menu-open_dark.svg)).

5. Click OK to confirm the download and installation settings.

When you click Apply or OK in the settings dialog, IntelliJ IDEA downloads and unpacks the selected Go SDK automatically.

![Download the Go SDK](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_ij_download_go_sdk_settings.png)

### Using asdf

You can use asdf to manage multiple Go versions for your projects. IntelliJ IDEA recognizes Go SDKs installed and managed through asdf, allowing you to switch between them directly in the IDE.

> **Note:**
> To use asdf as a Go SDK management tool, make sure you have installed [asdf](https://asdf-vm.com/guide/getting-started.html#_3-install-asdf) and the required Go versions via the [asdf installation guide](https://asdf-vm.com/guide/getting-started.html#_5-install-a-version).

asdf is a version manager that handles multiple programming languages and utilities. It lets you define different Go versions globally or per project directory:

* `asdf global`: sets the default Go version for the entire system.

* `asdf local`: sets the Go version for a specific project or directory.

IntelliJ IDEA supports both `asdf local` and `asdf global` configurations. You can also specify multiple versions, for example: `asdf local golang 1.21.0 1.20.8`. The IDE automatically detects the configured versions and displays them in the Go SDK list.

Procedure: Select an asdf-managed Go version for the project

1. Open settings (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) and navigate to `Go | GOROOT`.

2. From the list of available SDKs, select the Go version managed by asdf. If asdf is installed and configured, the versions it provides will appear automatically.

Once the version is selected, IntelliJ IDEA uses the corresponding Go SDK for building, running, and testing your project. You can change the version at any time using the same settings page or by updating your `.tool-versions` file in the project directory.

## GOPATH

The GOPATH variable defines the workspace where your Go projects, downloaded modules, and installed binaries are stored. You can configure it globally or per project and module, depending on your workflow.

In IntelliJ IDEA, GOPATH can be set at different scopes, allowing you to separate environments for various projects or SDK versions.

### Configuring GOPATH for different scopes

You can configure GOPATH for one of the following scopes:

> **Note:**
> If you configure multiple scopes, IntelliJ IDEA uses the most specific one (for example, module-level settings override project or global ones).

The IDE automatically sets the default GOPATH to `$HOME/go` on Unix systems and `%USERPROFILE%\go` on Windows. You can change it in the settings as described below.

Procedure: Configure GOPATH

1. Open settings (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) and navigate to `Go | GOPATH`.

2. Select the scope you want to configure:

* Global GOPATH: applies to all projects in the current installation of IntelliJ IDEA.

* Project GOPATH: applies only to the current project.

* Module GOPATH: applies to a specific module. Each module can use a different SDK or framework configuration.

3. Click Add (![the Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) to add a new path.

4. In the file browser, select the directory you want to associate with GOPATH. The selected path will be used to store downloaded modules, binaries, and caches.

![Configuring GOPATH for different scopes](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_configure_gopath.png)

When you apply the changes, IntelliJ IDEA updates the Go environment automatically. New paths are reflected in the project configuration and used by Go tools for imports, builds, and dependency management.

