But, we need to install Xcode first, after that we can type the following command to install Golang using Homebrew:
$ brew install golang
We can verify the installation using this command:
$ go version
Set Up Go WorkspaceWe need to setup our workspace, let start by creating folders:
$ mkdir -p $HOME/go/{bin,src,pkg}
After that, update .bash_profile with the following exports:
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
Reload bash profile by executing:
$ . ~/.bash_profile
Create Hello World Program
Let start writing go program, just to test our installation and setup by writing hello world program:
create hello.go any where, and type the following program:
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
to run the hello world program, type:
$ go run hello.go
And this program will output:
Hello World
No comments:
Post a Comment