WSL(WSL 2) - Windows Subsystem for Linux - is a compatibility layer for running Linux binary executables natively on Windows 10. Currently, it supports several Linux distributions, such as Ubuntu, OpenSUSE, and SLES.
Download and install a WSL distribution (for instance, Ubuntu) from Microsoft Store.
For this step, be sure to use Windows 10 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.
Upon the first launch of Ubuntu, 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 runEnable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Restart your computer.
From your home directory, download the tarball.wget https://dl.google.com/go/go1.16.linux-amd64.tar.gz
Extract the archive to /usr/local.tar -C /usr/local -xzf go1.16.linux-amd64.tar.gz
In your home directory (
cd ~), create the go folder.mkdir go
Configure GOPATH and GOROOT.export GOROOT=/usr/local/goexport GOPATH=$HOME/goexport 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.
Create a new project in the WSL file system
Install the needed JDK to the WSL environment using your favorite SDK manager.
On the welcome screen, click New Project.
Click the Browse button and navigate to the directory 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 \\wsl$ to the WSL file system.
GoLand creates a project located in WSL and you can develop and build your project inside the WSL environment without leaving the IDE.
Open a project stored in the WSL file system
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 \\wsl$ project location manually.
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.
The results of the code execution are displayed in the Run tool window. In the following example, we run the code from the Windows environment. And the output for our code is predictably
windows. But by using the WSL environment, we can change the output to
linux. For more information about how to change the environment, see Use the WSL environment for a project.
Use the WSL environment for a project
So, instead of the Windows environment that was used for running the app, we can use the WSL environment. So, if we run the previous example with the WSL target, we will get a different output for the operating system.
Create a run configuration for WSL
From the main menu, select. Alternatively, press Alt+Shift+F10, then 0.
In the Run/Debug Configuration dialog, click on the toolbar or press Alt+Insert..
From the Add New Configuration window, select the run/debug configuration that you want to create for running a target. It can be Go App Engine, Go Build, or Go Test.
From the Run on menu, under the New targets section, select WSL to add a WSL target.
In the New Target wizard, select your Linux distribution from the Linux distribution list. If the distribution was detected automatically and the introspection passed, press Next.
Check that the Go runtime configuration for WSL was detected correctly and click Finish.
Alternatively, type your own settings.
From the main menu, click Run and select the necessary run configuration or press (Shift+F10) to run your code and check the output in the Run tool window.