WIN10_WSL installation Golang
1 ~ WSL Installation
1. Open Win10 Bash on the Ubuntu on Windows feature
- Open
Windows设置
(shortcut key win+i) search应用和功能
- Select the relevant settings in the upper left
程序和功能
- In the new window, select
启用或关闭Windows功能
- In the conversation window, pull the scroll bar to the bottom, select
适用于Linux的 Windows 子系统
Click OK and wait for the system reboot to complete.
2. Choose your preferred Linux distribution
Open win10应用商店
Searchwsl
Choose获取这些应用
1.png
Pick a favorite Linux distribution
2.png
I chose OpenSUSE Leap 42.
Wait for the installation to complete when an icon is created in the Start menu
3.png
Several ways to open WSL
2 ~ Golang Installation
1. Download Golang
1. Download the tar file from code.google.com and extract it to the /usr/local
directory and /usr/local/go
Create the Go directory tree in. I downloaded it toD:/apps/
$ cd /mnt/d/apps$ // cd /mnt/[盘符/路径]$ sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz$ // sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz$ // 我安装的是10.3版本
- The tar command needs to run in root mode
- If you are unable to access Google, you can try to download from Golang China/Go language network and other learning exchange websites
2, setting environment variables
To /usr/local/go/bin
add to the PATH environment variable, you need to add this line to your $HOME/.profile
file:
$ sudo nano ~/.profile$ // sudo vi ~/.profileexport GOROOT=$HOME/goexport PATH=$PATH:$GOROOT/bin
3, set the working environment variable
- Create
go_work
a folder and add it to the$HOME/.profile
$ mkdir /mnt/c/go_work$ sudo nano ~/.profile$ // sudo vi ~/.profileexport GOPATH=/mnt/c/go_workexport PATH=$PATH:$GOPATH/bin
To see go_work
If the catalog was created successfully
Restart Terminal
4, test installation and work environment variable settings are correct
New in the work environmenthello.go
$ nano /mnt/c/go_work/src/github.com/soulmo/hello/hello.go$ // vi /mnt/c/go_work/src/github.com/soulmo/hello/hello.gopackage mainimport "fmt"func main() { fmt.Printf("hello, world\n")}
Then run it with the Go tool:
$ go -Versiongo version go1.10.3 linux/amd64$ go install hello.go$ hellohello, world
If you see the "Hello, World" message, then your go is properly installed, the system variable is set up correctly and asked a good question.
! Note that the go get
agent issue must be switched to the terminal environment to set up the Git agent
Q: Why write a tutorial
A: I did not find the WIN10-WSL installation Setup Golang tutorial, although it is no different from the Linux installation, but still want to write
Where is the root directory of the Q:WSL?
A: %USER%AppData\Local\Packages\[发行版]\
It is not recommended to change its files outside of the terminal environment, the permissions problem is a bit troublesome
Q:WSL Terminal recommendation
A:cmder toss a bit good use, but I use is wsl.exe and Vscode bring terminal (lazy toss, install a oh my zsh very good)