Setup Golang
$ curl -O https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz
$ tar -xvf go1.11.4.linux-amd64.tar.gz
- Move the contents to /usr/local directory
- Add the environmental variable GOPATH to .profile
cat <<EOF >>~/.profile
export GOPATH=\$HOME/work
export PATH=\$PATH:/usr/local/go/bin:\$GOPATH/bin
EOF
- Create the work directory
go version go1.11.4 linux/amd64
- Create a directory tree to map to a github repository
$ mkdir -p $GOPATH/src/github.com/ansilh/golang-demo
- Create a hello world golang program
$ vi $GOPATH/src/github.com/ansilh/golang-demo/main.go
package main
import "fmt"
func main(){
fmt.Println("Hello World.!")
}
- Build and install the program
go install github.com/ansilh/golang-demo
- Execute the program to see the output