Here, We will look into how to install and setup go on mac. You can follow given below steps to install and run go program on your mac.
Steps to install go on your mac:
- Run command on terminal: brew update
- brew install go or brew install go@latest
Add given below global variables into ~/.bashrc file. Default path of .bachrc file is ~/.bashrc.
export GOPATH=$HOME/go-workspace
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
Create your workspace:
mkdir $GOPATH
mkdir $GOPATH/src
mkdir $GOPATH/pkg
mkdir $GOPATH/bin
$GOPATH/src: Path to your go project
$GOPATH/pkg: contains every package objects
$GOPATH/bin: Path to compiled binaries
Sample go program:
package main
import "fmt"
func main() {
fmt.Println("hello go")
}
Output:
A02YZ14CLVEE:src admin$ go run sample.go
hello go
To learn more about golang, Please refer given below link:
https://www.techieindoor.com/go-lang-tutorial/
References:
https://golang.org/pkg/