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.
Select File | New | New Project.
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.
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.Click Create to create the project.
note
Make sure the Go plugin 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.
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.
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.

Press CtrlAlt0S to open settings and then select Languages & Frameworks | Go | Go Modules.
Select the Enable Go modules integration checkbox.
Click OK.
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.
Open settings by pressing CtrlAlt0S and navigate to Go | Go Modules.
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.
Ensure that Go modules integration is enabled. For more information, refer to Enable New project in a project.
In the Project tool window (View | Tool Windows | Project), double-click the MOD file.
Click a dependency declaration.
Press AltEnter 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 (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).
note
If you remove a dependency from the go.mod file, IntelliJ IDEA automatically removes it from the list of available libraries.
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 AltEnter, and select Fix missing dependencies.
Open settings by pressing CtrlAlt0S and navigate to Build, Execution, Deployment | Build Tools.
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.
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 Diagrams | Show Diagram.
tip
For more information about vendoring, refer to Vendoring.
In the Project tool window (View | Tool Windows | Project), double-click the go.mod file to open it in the editor.
Right-click a dependency import path and select Go To | Declaration or Usages Ctrl0B.
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 CtrlAlt0S 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.
Click the dependency and press AltEnter.
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.
Click the dependency and press AltEnter.
Select Show vulnerability info for <dependency>.
To adjust the scope or severity of these inspections, open settings (CtrlAlt0S) and navigate to Editor | Inspections | Go modules.
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 to a custom path such as/mod $WORK/modcache
.
tip
For more information about environment variables, refer to Environment variables at go.dev.
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.
Press CtrlAlt0S to open settings and then select Languages & Frameworks | Go Go modules.
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.
note
Ensure that the provided path to the folder with Go SDK includes bin and src folders.
Press CtrlAlt0S to open settings and then select Languages & Frameworks | 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.
Press CtrlAlt0S to open settings and then select Languages & Frameworks | 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.
Thanks for your feedback!