Skip to content

Instantly share code, notes, and snippets.

@VincentLiu
Last active June 29, 2020 17:53
Show Gist options
  • Save VincentLiu/fbc7bcb66223c2396b97aee6741a1584 to your computer and use it in GitHub Desktop.
Save VincentLiu/fbc7bcb66223c2396b97aee6741a1584 to your computer and use it in GitHub Desktop.
Install Golang on WSL

How to set up Go on WSL, Go environment and hello world Go application

  1. 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
  1. set up development folders
mkdir -p ~/go/src
mkdir -p ~/go/pkg
mkdir -p ~/go/bin
  1. 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
  1. check Go version and Go environment
source ~/.bashrc
go version
go env
  1. create hello.go
cd ~/go/src
vi hello.go 
package main

import "fmt"

func main() {
        fmt.Printf("Hello, world.\n")
}
  1. run hello.go
go run hello.go # output: Hello, world.
  1. 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment