Prerequisites:

  1. Advanced Windows 10 Home/Professional
  2. A VS Code installed on Windows 10
  3. You have Windows 2 on and downloaded Ubuntu 20.04 from the App store

** Make sure it’s WSL2!! ** Check version WSL-L-V, if not, WSL –set-version


, set the default and install WSL 2, WSL –set-default-version 2

This way you can put all your development environments on WSL2 and Windows 10 is just one…. Game consoles!

1 Download golang for Linux 64-bit

Download the recommended 7 zip package for Windows 10. Then open your Ubuntu, and when you get into the environment, all Windows 10 directories can be opened by/MNT /C disk/directory/file, and then you type a long mv to move to your favorite address/MNT /x disk/where you put your Go

2 Golang configuration

Use sudo chown -r with your username /etc command to give you permission to mess around in /etc. Messing around with /etc means you can edit the environment variable file profile using VS Code!

When you open vscode, it will detect that you have installed wsl2 and ask you to install the wsl2 plug-inAt the bottom of theSomething like this:Click green and select the second run releaseChoose your Ubuntu. Open file, open /etc, and scroll down to find profile (the profile.d folder is above, the files are below, be sure to scroll down !!!!!!!!!!!!!!!) Edit your environment variables: Chase! Add! Write! Into the!If you do not have permission, useSudo chown File name of the current user“And then, for convenience later, to transferChown root File name.Only one file is good, not the whole etc, your Linux will die!

Export GOROOT=/home/liu/go export GOPATH=/home/liu/work/go export GOPROXY=https://goproxy.cn // Environment variable export  PATH=$PATH:$GOROOT/bin:$GOPATH/binCopy the code

Refresh a wave source /etc/profile in the current command line code in Windows CMD type these restart:

// Run CMD >>net stop LxssManager // Stop >>net start LxssManager // as an administratorCopy the code

Is it ok to see the Go version?Thank you for looking up here, but you have to look down.

Install golang to enhance your VS Code

If, at this point, you open a Go file somewhere, your VS Code must tell you to install a bunch of tools that you click on and fail. Give gopath directory permission chmod 777-r work/

No! The enemy! Small! The skill! Qiao! In File->PreFerXXX-> Settings, click redAdd the following paragraph:

{
    "go.useLanguageServer": true,
}
Copy the code

Vscode in go mod code, instant smart! It can be used normally!

EOF