WSL
WSL (WSL 2) – Windows Subsystem for Linux – is a compatibility layer for running Linux binary executables natively on Windows 10 and later. Currently, it supports several Linux distributions, such as Ubuntu, OpenSUSE, and SLES.
note
You can also try to use Remote Development to configure WSL.
Download and install a WSL distribution (for instance, Ubuntu) from Microsoft Store.
For this step, be sure to use at least Windows 10 or later with the latest “Fall Creators Update” (minimum version 1709, build 16299.15). See the official guide Install the Windows Subsystem for Linux for instructions.
To work with WSL 2, your Windows version should be 10 build 18917 or later. Follow these instructions to switch the distributive.
Note that GoLand does not support legacy WSL, which you may have installed before upgrading your system to the build 16299.15 or later of Windows 10. In this case, you need to update your WSL distribution.
Run the Linux distribution.
Upon the first launch, the system may prompt you to enable the Windows optional feature. In this case, you need to do the following:
Open Windows PowerShell as Administrator and run
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Restart your computer.
note
If you are using Linux distribution other than Ubuntu, ensure that the distribution has the iproute2 package installed or install it manually once the WSL instance is deployed.
From your home directory, download the tarball.
wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz
Extract the archive to
/usr ./local tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz
In your home directory (
cd ~
), create the go folder.mkdir go
Configure GOPATH and GOROOT.
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin
You can create a project and store it in the WSL environment, open one from the WSL file system, and develop your projects further in WSL.
Install the needed Go version to the WSL environment.
note
You cannot use the Windows Go SDK for your WSL projects, ensure to select Go SDK that is installed in WSL. Alternatively, use run targets.
On the welcome screen, click New Project.
Click the Browse button and navigate to the directory in WSL where you want to create a new project.
In the Select Base Directory dialog, you can click the New Folder button (
) to create a folder for a project.
The project location for WSL will show the absolute path starting with
\ to the WSL file system.\wsl$ Click Create.
GoLand creates a project located in WSL and you can develop and build your project inside the WSL environment without leaving the IDE.
In GoLand, you can directly open a project stored in the WSL file system and work with it like with any other project.
Click the Browse button and navigate to the directory in the WSL file system that you want to open. Also, you can type the path to the
\ project location manually.\wsl$ note
You cannot use the Windows Go SDK for your WSL projects, ensure to select Go SDK that is installed in WSL. Alternatively, use run targets.
When you run code in your project, it is run in WSL. If you open the run configuration, note that GoLand refers to WSL as local machine.
![Run configuration Run configuration](https://resources.jetbrains.com/help/img/idea/2024.3/go_run_configuration_wsl.png)
The results of the code execution are displayed in the Run tool window.
To run Terminal in WSL configuration, open project Settings/Preference (CtrlAlt0S) and go to Tools | Terminal.
Specify the command in the Shell path field:
wsl.exe
to use the default Linux distributionwsl.exe -d <distribution name>
to use a specific Linux distribution
Click OK to save changes.
Switch to the Terminal tool window and type any command to inspect the output.
You can create or open your project locally on Windows and then run your compiled code in WSL using run targets. This might be helpful for the cross-platform development.
![Run tool window: WSL output Run tool window: WSL output](https://resources.jetbrains.com/help/img/idea/2024.3/go_wsl_change_target_to_wsl.png)
In the main menu, click Run | Manage Targets.
From the Add Target On window, select WSL.
In the New Target wizard, select your Linux distribution from the Linux distribution list. If the distribution was detected automatically and the introspection passed, click Next.
Check that the Go runtime configuration for WSL was detected correctly and click Finish.
Alternatively, type your own settings.
Go Executable: the path to the Go executable (for example,
/usr )/local /go /bin /go GOPATH: the path that defines the root of your workspace. A root directory must contain bin, pkg, and src subdirectories. (for example,
/home )/goprojects Version: a version number of your Go SDK (for example,
go1.15.8 linux/amd64
). GoLand detects this information automatically by runninggo version
.Additional settings: a group of settings that allow you to set directories for source code files and executables.
To run on a target, GoLand needs to upload to a target the following entities: source code files, files from a working directory, compiled binaries, and delve. If you do not specify paths in Additional Settings, the IDE will create random directories to store previously-mentioned files. See the following screenshot with randomly-generated directories for source files and executables.
You can specify the following options:
Project sources directory: a directory on a target where source code files are uploaded.
Compiled executables directory: a directory on a target that is used to store executables that your code produces.
In the Run Targets dialog, click the Project default target list and select the created configuration.
Run your application.
You need to perform the following steps to ensure that the building of a project works properly.
Run the Windows PowerShell as administrator.
Execute the following command to allow connections using WSL:
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
Then execute the command to renew the firewall rules:
Get-NetFirewallProfile -Name Public | Get-NetFirewallRule | where DisplayName -ILike "GoLand*" | Disable-NetFirewallRule
Now start the debugger session. When the Windows Firewall popup appears, select the Public networks checkbox.