
Installing Golang in WSL is a straightforward process that requires a few simple steps.
First, you need to install the Windows Subsystem for Linux (WSL) on your Windows 10 or 11 machine.
This can be done by enabling the Windows Subsystem for Linux feature in the Windows Features dialog box.
Open the Start menu and search for "Turn Windows features on or off."
Select the checkbox next to "Windows Subsystem for Linux" and click OK to save the changes.
Once WSL is installed, you can download the Golang installer from the official Golang website.
The installer is available for download as a zip archive, which you can extract to a folder of your choice.
Extract the Golang installer to a folder like `C:\Go` or `D:\Go`.
Next, you need to add the Go binary to your system's PATH environment variable.
This can be done by adding the path to the Go binary to the PATH variable in the System Properties dialog box.
Check this out: Install Elasticsearch Windows
Prerequisites
To get started with installing GoLang on WSL, you'll need to meet a few prerequisites.
First and foremost, you'll need to have WSL2 installed. Don't worry if you're not sure how to do this - it's actually pretty straightforward, and you can find a step-by-step guide in the installation guide.
Before we dive into the installation process, let's make sure you have WSL2 up and running. To do this, you'll need to refer to the installation guide for WSL2.
Broaden your view: Test Installation Matomo
WSL Options
You have two options to install WSL on your Windows 10 machine. You can either download and install it from the Microsoft Store or download and install it using the command line or a script.
To download and install WSL from the Microsoft Store, simply search for it and follow the installation prompts. Alternatively, you can use the command line to install WSL, which requires running PowerShell as an administrator and executing a specific command. The command, --install, enables additional components, downloads and installs the latest Linux kernel, sets WSL 2 as the default, and downloads and installs the Ubuntu Linux distribution.
Broaden your view: Golang Test Command
You'll be prompted to create a new user account when the installation is complete. This account will be a standard user account without administrative privileges, which is used by default when opening the distribution. You can choose any username and password you like, but be sure to choose one that you can easily remember, as you'll need it to access higher-level permissions using the sudo command.
WSL 1 vs WSL 2
WSL 1 and WSL 2 are two versions of the Windows Subsystem for Linux. WSL 1 is an older version that remains available if the standard installation leaves it on the first version.
You can install WSL 2 by default using the command --install in PowerShell with administrator rights. This command enables additional components, downloads and installs the latest Linux kernel, sets WSL 2 as the default, and downloads and installs the Ubuntu Linux distribution.
The command --install is a convenient way to install WSL 2, but you can also download and install it from the Microsoft Store or using the command line or script.
Broaden your view: Gcloud Api Using Golang
If you choose to install WSL 2 using the command --install, you'll be prompted to create a user account and password for Linux. This account is for a standard user without administrator rights, which will be used by default when you start the distribution.
You can choose any username and password for Linux, which does not have to be related to your Windows username. However, if you elevate the process privileges using sudo, you'll need to enter the password. It's a good idea to choose a password that you can easily remember.
If you find that your WSL installation is still on the first version after standard installation, you can refer to Step 4 for further instructions.
Curious to learn more? Check out: Tst Installation Matomo
Developing in WSL2
Developing in WSL2 is a great option for those who want to work with Go.
You can start by cloning a repository in WSL2, like the go-training/hello-world example, which involves navigating to the home directory with the command `cd ~`.
To create a new directory for your repositories, simply type `mkdir repos`.
Then, change into the new directory with `cd repos`.
After that, you can clone the repository with the command `git clone https://github.com/go-training/helloworld`.
On a similar theme: Html Template Golang
Development Environment
To install Go on WSL, you'll need to set up a development environment that includes the Go compiler and other necessary tools.
You can install the Go compiler by running the command `sudo apt update && sudo apt install golang-go` in your WSL terminal.
A Go development environment also requires a code editor or IDE, such as Visual Studio Code, which can be installed separately.
Explore further: Golang App Development
Edit BASHRC File
To edit the BASHRC file, you need to open it and add specific lines at the bottom.
You can open the file by following the steps outlined earlier.
Add the following lines to the bottom of the file: export GOROOT=/usr/local/go, export GOPATH=$HOME/go, and export PATH=$GOPATH/bin:$GOROOT/bin:$PATH.
Save the file after adding the lines.
To apply the changes, refresh your terminal using the bash command.
Readers also liked: Golang Go
Visual Studio Code
Visual Studio Code is a powerful code editor that allows you to edit files remotely.
You can install Visual Studio Code and then find the Remote WSL extension in the extensions tab.
To use Remote WSL, you'll need to install the extension after which you'll be able to connect to directories in WSL and edit files.
With Remote WSL, you'll have the ability to edit any files that are located in WSL.
Consider reading: Golang Source
Golang
Let's get started with installing Golang in WSL. If you have WSL2 and VSCode, you're all set. Head to the Golang website to find the latest stable version, which was go1.16.7 at the time of writing.
To download Golang, open your terminal in VSCode by pressing ctrl + ` and enter the following commands, replacing the version with the latest one available.
The latest stable version of Golang is go1.16.7.
You can check the version of Go by running the command `go version`.
A different take: Golang Version Manager
Install Go Tools
To get started with Go development, you'll need to install some essential tools. For debugging, you'll want to install dlv, which can be done with a single command: go install github.com/go-delve/delve/cmd/dlv@latest.
To install dlv, simply copy and paste the command into your terminal. This will download and install the latest version of dlv.
Featured Images: pexels.com


