IntelliJ IDEA 2025.1 Help

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 in your project. Read more about Go modules at go.dev.

Create a Go project

  1. Select File | New | New Project.

    Alternatively, click New Project in 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) 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.

  6. Click Create to create the project.

    Download Go SDK

Change the IML file location for Go projects

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.

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

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

Enable Go modules in a project

  1. Press Ctrl+Alt+S 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

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.

Disable automatic download of Go module dependencies

  1. Open settings by pressing Ctrl+Alt+S 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

Synchronize dependencies from go.mod

  1. Ensure that Go modules integration is enabled. For more information, refer to Enable New project 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 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

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.

  2. Click a dependency in the import section, press Alt+Enter, and select Fix missing dependencies.

    Fetch dependencies

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

  1. Open settings by pressing Ctrl+Alt+S 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) to apply and load the updates manually.

      Load Go modules Changes icon
    • 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.

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
  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.

    Navigate from a dependency import path to package source files

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.

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.

Update dependencies

  • Click the dependency and press Alt+Enter.

    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.

Show vulnerability information about dependencies

  1. Click the dependency and press Alt+Enter.

  2. Select Show vulnerability info for <dependency>.

Customize inspection settings

  • To adjust the scope or severity of these inspections, open settings (Ctrl+Alt+S) 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.

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.

Introduce an environment variable in a project

  1. Press Ctrl+Alt+S 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) and choose the template you want to add.

    Introduce an environment variable in a new project

Installing Go SDK

Select a local copy of the Go SDK

  1. Press Ctrl+Alt+S to open settings and then select Languages & Frameworks | 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.

    Installing Go SDK

Download the Go SDK

  1. Press Ctrl+Alt+S to open settings and then select Languages & Frameworks | Go | GOROOT.

  2. Click the Add SDK button (the Add SDK button) 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.

    Installing Go SDK
Last modified: 08 April 2025