Windows 11 was just released a few days ago and GoLand introduces support for projects inside the WSL2 mount and it is available in the Early Access Program. It is a good time to get started and combine things for modern Go development step-by-step.
I will show you a small introduction to configure WSL2 and GoLand, how to install Go SDK and open projects inside WSL2 mounts. First off, we have to install WSL2 under Windows 11. There are a few steps to consider.
First off, we are going to install WSL2 itself via
wsl --install in PowerShell with admin rights. The operation takes a bit of time and at the end of it, you can see the successful message: The requested operation is successful. Changes will not be effective until the system is rebooted.
I would say that the process of installing WSL2 in Windows 11 is much easier than earlier. One command does all things.
After that, open Ubuntu distribution (or change to a different one using Microsoft article), enter username, password and install Go SDK.
There are a few ways to install Go SDK:
I prefer an official guide. It is pretty well documented and easy to start. Pay attention that it requires sudo privileges for the user.
wget -c https://golang.org/dl/go1.17.1.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
A few preparations to use it:
$PATHchanges to the current shell session:
To confirm that Go is configured properly, we can execute
go version and should get the following output:
go version go1.17.1 linux/amd64
We are good to go to the next section.
Let's create our project right from GoLand. On Welcome Screen, select New Project and specify project location under WSL2 mount. You can create directories from the pop-up by right-clicking on the root folder. Make sure that the path to the project contains
GoLand highlights a warning and requires Go SDK in WSL. We can click on the Plus icon and choose Local, then find Go SDK (
\\wsl$\Ubuntu\usr\local\go by default). Create a project and wait for Go SDK indexing.
As an example, I take Go by Example: Interfaces code snippet. Let's run it via gutter icons around
main() function. After that, try to debug a bit.
We've configured all necessary environments to get developer things done. 🎉
We can use WSL2 and GoLand for Go development for now. It is much easier to get started and separate personal and development environments. As a benefit of Windows 11, we can run GUI apps inside WSL2 and it looks really promising.