This article introduces the installation of Windows10 subsystem Linux(WSL) and the use of Goland, vscode, I feel WSL makes background development become very convenient, hereby share. The original article is at Github Golang Project
WSL(Windows Subsystem for Linux) installation and use
Official introduction: WSL(Windows Subsystem for Linux) is a Windows Subsystem for Linux. It is a compatibility layer for natively running Linux binary executables on Windows 10 and Windows Server 2019. Frankly speaking, it is possible to directly compile executable files in Linux environment in Windows10 by WSL, so that the development under Windows has a chance to get rid of the huge virtual machine. It has a feeling of developing under MAC, which is especially suitable for poor code farmers like me who do not have MAC.
Enable subsystem functions
Win10 Power shell input the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Copy the code
Win10 install Ubuntu
Install Ubuntu from the Windows 10 App Store:
Win10 desktop will prompt you to set user name and password:
GO Environment Configuration
GOROOT configuration
Configuring a Shared Directory
To easily copy files between Windows and WSL, set the shared directory first. The/MNT /c/Users/HideOnBush/ path in WSL is the mount partition of Windows10 under Linux. To facilitate the sharing of files with Windows10, create the UbuntuShare folder in Windows and add the soft link in WSL:
ln -s /mnt/c/Users/HideOnBush/UbuntuShare/ win10
Copy the code
HideOnBush is my Windows user name, it needs to be replaced by your actual Windows user name.
WSL installation Go
Download the Linux GO installation package from Go Chinese (I used 1.12.5), place it in the shared directory you just set up, and you’re ready to play in the WSL. Unzip to /usr/local:
CD win10 sudo tar -xzf go1.12.5.linux-amd64.tar.gz -c /usr/local/Copy the code
GOPATH configuration
Windows and Linux GOPATH set to the same path, you can achieve in Windows 10 code and Linux code to share a set of third-party packages.
View win10 environment variables
Users/HideOnBush/go
Set WSL GOPATH:
vim ~/.bashrc
Copy the code
Add at the end:
export GOPATH=/mnt/c/Users/HideOnBush/go
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
Copy the code
To make the modification effective immediately:
source .bashrc
Copy the code
Run the go env command to check whether GOPATH is configured successfully:
Updating software Sources
sudo cp /etc/apt/sources.list /etc/apt/sources.list_origin
sudo vim /etc/apt/sources.list
Copy the code
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
Copy the code
Sudo apt-get upgrade sudo apt-get upgrade // Update the software according to the information of the software sourceCopy the code
Call WSL bash in Windows
Next, depending on which compiler you are using, change the bash used by the compiler to bash in WSL to compile the Linux executable under Windows.
Use with Goland
Change bash to the WSL path
Find the path to the WSL command line,
Set goland “shell path”,
Terminal test,
You can’t run it directly using Goland’s run icon, because Goland uses the Windows build environment by default, and you must compile in Terminal to use WSL’s bash build.
Use with VS Code
After installing the WSL, you can see the Windows system Linux (WSL) window in vscode terminal, where you can easily operate Linux.
To prevent conflicts with file newlines written in Linux, it is recommended to change the newline character to Linux style, as follows:
So far, the Linux subsystem development environment of Windows10 has been basically built. You can install the corresponding tools in WSL according to your needs. If you feel that the COMMAND line of WSL is too difficult to use, you can use Goland terminal or SSH tools such as Secure CRT.