# Go

By default, IntelliJ IDEA suggests creating a Go modules project. With Go modules, you do not need to keep your project files under GOPATH and [can easily manage dependencies](#working-with-dependencies) in your project. Read more about Go modules at [go.dev](https://go.dev/blog/using-go-modules).

Procedure: Create a Go project

1. Select `File | New | {0, choice, 0#New |1#}{1, choice, 0#Java |1#}Project…`.

Alternatively, navigate to New | Project on the Welcome to IntelliJ IDEA dialog.

2. In the New Project dialog, select New project from the list of available project types.

Ensure that Go is selected as the project language in the Language list.

3. In the GOROOT field, specify the location of your Go installation. IntelliJ IDEA usually detects this location automatically.

To change or install a new Go SDK version, click Add SDK (![Add SDK icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.add.svg)) and choose one of the following options:

* Local: to use an existing SDK from your local system.

* Download: to download a Go SDK version from the official repository.

4. (Optional) Select or clear the Enable vendoring support automatically checkbox to enable or disable vendoring support.

5. (Optional) In the Environment field, specify any environment variables your project requires. For example, `GOPROXY`.

To learn more, refer to the [Environment variables section](#environment-variables).

> **Note:**
> Do not use this field to set tags for the `GOEXPERIMENT` variable. Instead, use the Experiments field in the Build Tags settings. For details, see [Using Go experiments](configuring-build-constraints-and-vendoring.html#using_go_experiments).

6. Click Create to create the project.

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

## Change the IML file location for Go projects

> **Note:**
> Make sure the [Go plugin](https://plugins.jetbrains.com/plugin/9568-go) is installed and enabled.

When you create a Go project in IntelliJ IDEA, you can specify a directory for the `.iml` file. By default, the file is created in the root directory of the project.

To change the IML file location for an existing Go project in IntelliJ IDEA, you need to update the `modules.xml` file inside the `.idea` directory.

Procedure: Change the IML file location for existing Go projects

1. In the Project tool window, open the `.idea` folder of the project.

2. Update the `fileurl` and `filepath` attributes in the `modules.xml` file so that both point to the new IML file location inside `.idea/`.

3. Move the IML file into the `.idea` directory.

![Change the IML file location for existing Go projects](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_change_the_iml_file_location_in_modules_xml.png)

## Using Go modules in your project

In the Project tool window (`View | Tool Windows | Project`), Go modules are displayed with their full import path. The version of each Go Module is shown in a dimmed font color to help you distinguish between them.

![Go Module is shown in a dimmed font color](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_module_is_shown_in_a_dimmed_font_color.png)

Procedure: Enable Go modules in a project

1. Press `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)) to open settings and then select `Languages & Frameworks | Go | Go Modules`.

2. Select the Enable Go modules integration checkbox.

3. Click OK.

![Enable New project in a project](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_ij_enable_go_modules.png)

## Working with dependencies

By default, IntelliJ IDEA downloads all the necessary dependencies when you open a project or modify `go.mod`. You can configure this behavior in settings.

Procedure: Disable automatic download of Go module dependencies

1. Open settings by pressing `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 | Go Modules`.

2. Click the Download Go module dependencies drop-down and select the required option. You can choose from the following:

* Enable for all projects: enables automatic downloading of Go module dependencies for all projects. This is the default setting. The IDE runs `go mod download` after each `go list -m` execution. Disable this option if you have a limited internet connection or prefer to download dependencies manually.

* Disable for all projects: disables automatic downloading of Go module dependencies for all projects.

* Enable for current project, disable for other projects: enables automatic downloading of dependencies only for the current project. New projects will default to Disable for all projects.

* Disable for current project, enable for other projects: disables automatic downloading of dependencies only for the current project. New projects will default to Enable for all projects.

![Automatic download of Go modules](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_automatic_download_of_go_modules.png)

Procedure: Synchronize dependencies from go.mod

1. Ensure that Go modules integration is enabled. For more information, refer to [Enable New project in a project](#enable-go-modules-in-a-project).

2. In the Project tool window (`View | Tool Windows | Project`), double-click the MOD file.

3. Click a dependency declaration.

4. Press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)) and select the action you want to perform. Available options:

* Fix missing dependencies: fetches and downloads missing dependencies and removes unused ones by calling `go mod tidy` or `go mod vendor`. Dependencies listed in `replace` directives are not fetched or removed. Unused dependencies in `replace` directives are marked in red. This is not an error and does not affect application behavior.

* Download all modules to the module cache: fetches and downloads all missing dependencies and shows them under External Libraries in the Project tool window (`View | Tool Windows | Project`).

* Download <module_name> to the module cache: fetches and downloads the selected module. It appears under External Libraries in the Project tool window (`View | Tool Windows | Project`).

![Download all modules to the module cache](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_download_all_modules_to_the_module_cache.png)

> **Note:**
> If you remove a dependency from the `go.mod` file, IntelliJ IDEA automatically removes it from the list of available libraries.

Procedure: Synchronize dependencies from the opened Go file

1. Ensure that Go modules integration is enabled. For more information, refer to [Enable New project in a project](#enable-go-modules-in-a-project).

2. Click a dependency in the `import` section, press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)), and select Fix missing dependencies.

![Fetch dependencies](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_fetch_dependencies_go_modules.png)

Procedure: Configure automatic run of 'go list' for 'go.mod'

1. Open settings by pressing `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 `Build, Execution, Deployment | Build Tools`.

2. Select or clear the Sync project after changes in the build scripts option.

3. Depending on your workflow, choose one of the following options:

* Any changes: runs `go list` after any modification to `go.mod`. By default, IntelliJ IDEA uses this option to run `go list` automatically whenever `go.mod` changes.

* External changes: disables automatic execution of `go list` when editing the file inside the IDE. After making changes, click the Load Go modules Changes icon (![the Load Go modules Changes icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.buildLoadChanges.svg)) to apply and load the updates manually. ![Load Go modules Changes icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_load_go_modules_changes_icon.png)

* If you do not want to run `go list` after any modification of `go.mod`, clear the Sync project after changes in the build scripts checkbox. With this option disabled, you will see the Load Go modules Changes icon for all changes, both internal and external.

Procedure: Create a diagram of dependencies

The `go.mod` file lists the dependencies used in your project. You can use it to generate a visual diagram of these dependencies.

1. Make sure that New project is enabled in your project.

2. Right-click the `go.mod` file and select `Diagrams | Show Diagram`.

![Create a diagram of dependencies](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_create_a_diagram_of_dependencies.png)

> **Tip:**
> For more information about vendoring, refer to [Vendoring](configuring-build-constraints-and-vendoring.html#vendoring).

Procedure: Navigate from a dependency import path to package source files

1. In the Project tool window (`View | Tool Windows | Project`), double-click the `go.mod` file to open it in the editor.

2. Right-click a dependency import path and select `Go To | Declaration or Usages` `Ctrl+B` (Windows), `⌘ B` (macOS), `⌘ B` (IntelliJ IDEA Classic (macOS)), `⌘ B` (macOS System Shortcuts), `Ctrl+B` (XWin), `Ctrl+B` (GNOME), `Ctrl+B` (KDE), `Ctrl+Alt+G` (Emacs), `F12` (Sublime Text), `F12` (Sublime Text (macOS)), `Ctrl+B` (NetBeans), `F12` (Visual Studio), `F12` (Visual Studio (macOS)), `F3` (Eclipse), `F3` (Eclipse (macOS)).

![Navigate from a dependency import path to package source files](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_navigate_to_sources_from_go_mod.png)

### Updating dependencies in go.mod

When you open the `go.mod` file, IntelliJ IDEA highlights outdated dependencies. You can click the inlay hint to apply a quick-fix and update the dependency.

> **Note:**
> If you do not see inlay hints, open settings by pressing `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 `Editor | Inlay Hints`. Under the Code Vision node, make sure the Update dependencies checkbox is selected.

You can also update all dependencies at once—either to the latest patch version or to the latest available version. If needed, you can limit updates to direct dependencies only.

IntelliJ IDEA also includes inspections for deprecated and retracted versions:

* Deprecated dependency: marked with strikethrough text. Indicates that the dependency is deprecated.

* Retracted dependency version: also marked with strikethrough text. Indicates that the version has been retracted.

Procedure: Update dependencies

* Click the dependency and press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)).

Select the appropriate intention action:

* Change <dependency> version to <new_version>: updates the selected version to the nearest one that includes a fix for a known vulnerability. This is not necessarily the latest version.

* Update all dependencies to latest patch version: updates all vulnerable versions to their latest patch version, which includes bug fixes and backward-compatible changes.

* Update all dependencies to latest version: updates all vulnerable versions to the most recent available versions.

* Update direct dependencies to latest patch version: updates all direct dependencies to their latest patch versions. A direct dependency is a module that appears in an `import` statement in your source files.

* Update direct dependencies to latest version: updates all direct dependencies to their most recent versions.

Procedure: Show vulnerability information about dependencies

1. Click the dependency and press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)).

2. Select Show vulnerability info for <dependency>.

Procedure: Customize inspection settings

* To adjust the scope or severity of these inspections, 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 `Editor | Inspections | Go modules`.

## Environment variables

Environment variables provide a way to configure application execution parameters. They can be used to store proxy server addresses for downloading dependencies (`GOPROXY`), define private packages (`GOPRIVATE`), and set other relevant values. In IntelliJ IDEA, you can use the following templates for environment variables:

* GOPROXY: specifies the proxy servers used to download dependencies when running the `go` command.

* GOSUMDB: specifies the checksum database used to verify that packages listed in the `go.sum` file are trusted.

* GOPRIVATE: lists the modules considered private. The `go` command skips proxy and checksum verification for these modules.

* GONOPROXY: lists private modules that should not use proxy servers. This variable overrides `GOPRIVATE` for proxy settings.

* GONOSUMDB: lists private modules for which checksum validation is skipped. This variable overrides `GOPRIVATE` for checksum settings.

* Other: use this option to define custom variables. For example, `GOMODCACHE` can be used to change the default module cache location from `$GOPATH/pkg/mod` to a custom path such as `$WORK/modcache`.

> **Tip:**
> For more information about environment variables, refer to [Environment variables at go.dev](https://go.dev/ref/mod#environment-variables).

IntelliJ IDEA also automatically detects Go module–related system environment variables and displays them in the Environment variables dialog, under the System environment variables section.

Procedure: Introduce an environment variable in a project

1. Press `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)) to open settings and then select `Languages & Frameworks | Go Go modules`.

2. In the Environment field, click the Browse icon at the end of the field.

3. In the Environment variables window, click the Add button (![the Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) and choose the template you want to add.

![Introduce an environment variable in a new project](https://resources.jetbrains.com.cn/help/img/idea/2026.2/go_introduce_an_environment_variable.png)

## Installing Go SDK

> **Note:**
> Ensure that the provided path to the folder with Go SDK includes `bin` and `src` folders.

Procedure: Select a local copy of the Go SDK

1. Press `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)) to open settings and then select `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)) and select Local….

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

4. Click Open.

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

Procedure: Download the Go SDK

1. Press `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)) to open settings and then select `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)) 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.menu-open_dark.svg)).

5. Click OK.

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

