Wednesday, August 8, 2018

GO lang on Ubuntu 16.04

Downloading and installing Go 1.9.1, Setup environment, building a simple Hello World application

Download and setup

curl -O https://storage.googleapis.com/golang/go1.9.1.linux-amd64.tar.gz
tar -xvf go1.9.1.linux-amd64.tar.gz
sudo mv go /usr/local 

Setting path

vim ~./profile
#add as last line
export PATH=$PATH:/usr/local/go/bin

Init

source ~/.profile

Test

mkdir $HOME/gowork
mkdir -p $HOME/gowork/src/hello

Set gopath

export GOPATH=$HOME/gowork

Write hello.go

Note: save under $HOME/gowork/src/hello

package main
import "fmt"
func main() {
     fmt.Printf("hello, world\n")
}

Compile and run 

use run, compile or install
from source folder run
go run hello.go
#or
go build hello.go
./hello

cd $GOPATH
go install hello
#run
$GOPATH/bin/hello

Install and config Go extension on VSCode

This extension uses a set of Go tools to provide the various rich features. These tools are installed in your GOPATH by default

settings

"go.gopath": "/home/user/gowork"

 

 

Reference

Install Go 1.9.1 on Ubuntu 16.04

No comments: