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
Select
.Alternatively, click New Project in the Welcome to IntelliJ IDEA dialog.
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.
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 (
) 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.
(Optional) Select or clear the Enable vendoring support automatically checkbox to enable or disable vendoring support.
(Optional) In the Environment field, specify any environment variables your project requires. For example,
GOPROXY
.To learn more, refer to the Environment variables section.
Click Create to create the project.
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
In the Project tool window, open the .idea folder of the project.
Update the
fileurl
andfilepath
attributes in the modules.xml file so that both point to the new IML file location inside .idea/.Move the IML file into the .idea directory.
Using Go modules in your project
In the Project tool window ( ), 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.

Enable Go modules in a project
Press Ctrl+Alt+S to open settings and then select
.Select the Enable Go modules integration checkbox.
Click OK.
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
Open settings by pressing Ctrl+Alt+S and navigate to
.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 eachgo 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.
Synchronize dependencies from go.mod
Ensure that Go modules integration is enabled. For more information, refer to Enable New project in a project.
In the Project tool window ( ), double-click the MOD file.
Click a dependency declaration.
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
orgo mod vendor
. Dependencies listed inreplace
directives are not fetched or removed. Unused dependencies inreplace
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 ( ).
Download <module_name> to the module cache: fetches and downloads the selected module. It appears under External Libraries in the Project tool window ( ).
Synchronize dependencies from the opened Go file
Ensure that Go modules integration is enabled. For more information, refer to Enable New project in a project.
Click a dependency in the
import
section, press Alt+Enter, and select Fix missing dependencies.
Configure automatic run of 'go list' for 'go.mod'
Open settings by pressing Ctrl+Alt+S and navigate to
.Select or clear the Sync project after changes in the build scripts option.
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 rungo 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 () to apply and load the updates manually.
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.
Make sure that New project is enabled in your project.
Right-click the go.mod file and select .
Navigate from a dependency import path to package source files
In the Project tool window ( ), double-click the go.mod file to open it in the editor.
Right-click a dependency import path and select
Ctrl+B.
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
Click the dependency and press Alt+Enter.
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
.
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
Press Ctrl+Alt+S to open settings and then select
.In the Environment field, click the Browse icon at the end of the field.
In the Environment variables window, click the Add button (
) and choose the template you want to add.
Installing Go SDK
Select a local copy of the Go SDK
Press Ctrl+Alt+S to open settings and then select
.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.
Download the Go SDK
Press Ctrl+Alt+S to open settings and then select
.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.