How to set up Go on WSL, Go environment and hello world Go application
- install Go from here
wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.10.linux-amd64.tar.gz- set up development folders
mkdir -p ~/go/src
mkdir -p ~/go/pkg
mkdir -p ~/go/bin- set up GOPATH & GOBIN
add the following lines to ~/.bashrc
export GOPATH=$HOME/go
export GOBIN=$HOME/go/bin
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin- check Go version and Go environment
source ~/.bashrc
go version
go env- create hello.go
cd ~/go/src
vi hello.go package main
import "fmt"
func main() {
        fmt.Printf("Hello, world.\n")
}
- run hello.go
go run hello.go # output: Hello, world.- build and install hello.go
go build hello.go   # create a new file hello on the same directory
./hello             # output: Hello, world.
hello               # -bash: /home/you/go/bin/hello: No such file or directory
go install hello.go # create a new file hello on ~/go/bin directory
hello               # output: Hello, world.
can't load package: package github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest: cannot find package "github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest" in any of:
/usr/local/go/src/github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest (from $GOROOT)
/home/onexploit/go/src/github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest (from $GOPATH)