Setting Up the Go Programming Environment on Windows 11
Tags: go, docker, wsl2, vscode
Published: 2023-11-16 14:45:52

Go is a statically typed and compiled high-level programming language crafted at Google to address various programming challenges, including multi-core processing, networking, computing clusters, and web development models.

The syntax of Go resembles a user interface in the language. It boasts a clean, straightforward, and easily understandable structure. Unlike some languages, Go omits default parameters and conventional private and public keywords. Instead, it relies on the initial letter of an identifier to discern its visibility.

### Start developing Golang

Before delving into the fascinating problem-solving aspects and syntax of Golang, let's initiate our journey by setting up this language on various operating systems. For the purpose of this guide, we will be using Windows 11.

### Install Ubuntu on WSL2
With the Windows Subsystem for Linux (WSL), developers can harness the capabilities of both the Windows and Linux operating systems.

Open the Windows Terminal and utilize it to install Ubuntu.
```
wsl --install -d Ubuntu
```

### Install Docker desktop
Simple click to download [https://www.docker.com/products/docker-desktop/](https://www.docker.com/products/docker-desktop/)
Once downloaded and installed, open Docker Desktop and navigate to `Settings -> Resources -> WSL Integration`, then enable `Ubuntu`.

Return to the WSL terminal, and witness the magic with the command:
```
docker ps
```

### Install gvm
Install GVM, which offers an interface for managing Go versions, by executing the following command:
```
sudo apt-get update
sudo apt-get install bison
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
```
Install Go and set the version to 1.21.4 using the following commands:
```
gvm install go1.21.4 -B
gvm use go1.21.4 --default
```
Switching to other Go versions is easy; simply use the two commands mentioned above.

### Start develop with vscode
Dowload here: [https://code.visualstudio.com/](https://code.visualstudio.com/)

Open Visual Studio Code, and install the `Go` and `WSL` extensions. Choose `Open a Remote Window.`

### Hello World in Golang
Create a directory and navigate into it. Run the following command to initialize your Golang project:

```
go mod init github.com/reluth/hello-world
```

Create `main.go`
```go
package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello World!")
}
```

Open your terminal and run:

```
go run main.go
```

Output: `Hello World!`

### Conclusion 
Congratulations on completing the initial steps to set up your Go development environment on Windows 11! 

By installing WSL2, Docker Desktop, GVM, and configuring Visual Studio Code, you've laid a solid foundation for building Go applications.

Feel free to explore more advanced features of Go, leverage its concurrency model, and tap into the rich ecosystem of libraries and tools available. Happy coding!

### 

### Reference
* [Go (programming language)](https://en.wikipedia.org/wiki/Go_(programming_language))
* [Go at Google: Language Design in the Service of Software Engineering](https://go.dev/talks/2012/splash.article)
* [Installing WSL and Docker in Windows 11](https://www.youtube.com/watch?v=e6uyGCoLiWA&ab_channel=ProgrammingwithJohn)
* [Go Version Manager](https://github.com/moovweb/gvm)