DEV Community

Cover image for First Glance: WSL2 & GoLand on Windows 11
John Doe
John Doe

Posted on

First Glance: WSL2 & GoLand on Windows 11

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.

Configure WSL2 on Windows 11

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.

Install Go SDK under WSL2

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
Enter fullscreen mode Exit fullscreen mode

A few preparations to use it:

  • Specify export PATH=$PATH:/usr/local/go/bin under $HOME/.profile.
  • Load $PATH changes to the current shell session: source ~/.profile.

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
Enter fullscreen mode Exit fullscreen mode

We are good to go to the next section.

Project opening in GoLand

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 \\wsl$ prefix:

\\wsl$\Ubuntu\home\s0xzwasd\Projects\Go\dev-to-example
Enter fullscreen mode Exit fullscreen mode

An option to create directories in GoLand

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.

GoLand runs code from WSL2 mount

We've configured all necessary environments to get developer things done. 🎉

Limitations

So, there are several limitations at the moment, especially symlinks and File Watchers are not supported (IDEA-253253, WEB-38925) as well as External Tools (IDEA-201045) and Mozilla RR (GITHUB-2506).

Conclusion

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.

Top comments (0)