Experience: is what you get soon after you need it.

Experience: is what you get soon after you need it.

Rasul Allah (sal Allahu alaihi wa sallam) said: "Restore the trusts of those who trust you, and deal not falsely with him who deals falsely with you." [Abu Dawud, Tirmidhi]

Search This Blog

Thursday, October 8, 2015

How to install go on MAC


How to install
go
on MAC

Download

Download it from → https://golang.org/dl/


Pick the OS.


Download the package



Open the downloaded package:


Click “Continue”

Select “all users” → Click “Continue”

Click “Instal”



Enter “Password” → Click “Instal Software”


Wait for the install to complete

Summary:

That’s it you are done.




Package Details:

The package installs the Go distribution under  /usr/local/go.

shaiks@MAC$ls -lrt /usr/local/go/
total 168
drwxr-xr-x    7 root  wheel    238 Sep  8 21:31 pkg
drwxr-xr-x   15 root  wheel    510 Sep  8 21:31 misc
drwxr-xr-x    3 root  wheel    102 Sep  8 21:31 lib
-rw-r--r--    1 root  wheel   1150 Sep  8 21:31 favicon.ico
drwxr-xr-x   39 root  wheel   1326 Sep  8 21:31 doc
drwxr-xr-x    4 root  wheel    136 Sep  8 21:31 blog
drwxr-xr-x    5 root  wheel    170 Sep  8 21:31 bin
drwxr-xr-x   11 root  wheel    374 Sep  8 21:31 api
-rw-r--r--    1 root  wheel      7 Sep  8 21:31 VERSION
-rw-r--r--    1 root  wheel   1519 Sep  8 21:31 README.md
-rw-r--r--    1 root  wheel   1303 Sep  8 21:31 PATENTS
-rw-r--r--    1 root  wheel   1479 Sep  8 21:31 LICENSE
-rw-r--r--    1 root  wheel  28953 Sep  8 21:31 CONTRIBUTORS
-rw-r--r--    1 root  wheel   1107 Sep  8 21:31 CONTRIBUTING.md
-rw-r--r--    1 root  wheel  21146 Sep  8 21:31 AUTHORS
drwxr-xr-x  234 root  wheel   7956 Sep  8 21:32 test
drwxr-xr-x   63 root  wheel   2142 Sep  8 21:32 src
-rw-r--r--    1 root  wheel     26 Sep  8 21:32 robots.txt


The package should put the /usr/local/go/bin directory in your PATH environment variable. You may need to restart any open Terminal sessions for the change to take effect.

shaiks@MAC$echo $PATH
/usr/local/git/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/go/bin


Create Project Workspace:


shaiks@MAC$mkdir $HOME/mygo
          
shaiks@MAC$echo "export GOPATH=$HOME/mygo" >> ~/.profile
shaiks@MAC$echo "export GOBIN=$GOPATH/bin" >> ~/.profile

shaiks@MAC$cat .profile | grep GO
export GOPATH=/Users/shaiksameer/mygo
export GOBIN=$GOPATH/bin

Test go:


shaiks@MAC$pwd
/Users/shaiksameer/mygo

shaiks@MAC$mkdir -p src/hello

shaiks@MAC$pwd
/Users/shaiksameer/mygo/src

Create a sample program
shaiks@MAC$vi /Users/shaiksameer/mygo/src/hello/hello.go
package main

import "fmt"

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


shaiks@MAC$cd ..

shaiks@MAC$go install src/hello/hello.go

It creates a bin directory and executable file called “hello” under bin directory.

Execute the little program from the bin dir:

shaiks@MAC$./bin/hello
hello, world

Or Use compile & run in single command.

shaiks@MAC$go run src/hello/hello.go
Hey!
Mr. Sameer Shaik

Resources:

No comments: