Go or golang, is a programming language initially developed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. Just like Linux kernel it has many contributors from the open source community. From the official project site:
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Go is distributed under a BSD-style license. It is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It’s a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.
Install Xcode and gcc
First, you need to use the gcc that comes with Xcode. See how to install and use Xcode on Apple Mac OS X for more information.Installing Golang on Mac OS X
Google provides the package file for OS X. All you have to do is visit this page and grab the latest version. Once downloaded, open it, and follow the prompts to install the Go tools. The package installs the Go distribution to /usr/local/go directory:
- Golang installing on OS X using wizard
- Golang install # 2
- Golang install # 3
- Golang – enter admin password
- Golang install # 5
- Golang install Completed
Verify your installation
Open the Terminal and type the following commands:
$ ls -l /usr/local/go
Sample outputs:
total 120 -rw-r--r-- 1 root wheel 13577 Nov 29 03:13 AUTHORS -rw-r--r-- 1 root wheel 19578 Nov 29 03:13 CONTRIBUTORS -rw-r--r-- 1 root wheel 1479 Nov 29 03:13 LICENSE -rw-r--r-- 1 root wheel 1303 Nov 29 03:13 PATENTS -rw-r--r-- 1 root wheel 1112 Nov 29 03:13 README -rw-r--r-- 1 root wheel 5 Nov 29 03:16 VERSION drwxr-xr-x 2 root wheel 272 Nov 29 03:13 api drwxr-xr-x 2 root wheel 170 Nov 29 03:15 bin drwxr-xr-x 4 root wheel 136 Nov 29 03:15 blog drwxr-xr-x 8 root wheel 1292 Nov 29 03:13 doc -rw-r--r-- 1 root wheel 1150 Nov 29 03:13 favicon.ico drwxr-xr-x 3 root wheel 510 Nov 29 03:13 include drwxr-xr-x 3 root wheel 102 Nov 29 03:13 lib drwxr-xr-x 22 root wheel 816 Nov 29 03:16 misc drwxr-xr-x 6 root wheel 204 Nov 29 03:14 pkg -rw-r--r-- 1 root wheel 26 Nov 29 03:13 robots.txt drwxr-xr-x 7 root wheel 782 Nov 29 03:13 src drwxr-xr-x 16 root wheel 6800 Nov 29 03:13 test
Type the following command to display Go environment information:
$ go env
Sample outputs:
GOARCH="amd64" GOBIN="" GOCHAR="6" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" TERM="dumb" CC="gcc" GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common" CXX="g++" CGO_ENABLED="1"
Writing your first Go program
Create a text file called hello.go using a text editor such as vi/vim:
$ vi hello.go
Append the following code:
/* hello.go - My first Golang program */ package main import "fmt" func main() { fmt.Printf("Hello, world\n") }
Test and run hello.go, enter:
$ go run hello.go
Sample outputs:
Hello, world
To build an executable i.e. compile packages and dependencies into an executable file, enter:
$ go build hello.go
You will get an executable file called hello in the current directory:
$ ls -l hello -rwxr-xr-x 1 vivek wheel 2188368 Dec 2 16:07 hello $ file hello hello: Mach-O 64-bit executable x86_64
You can run hello program as follows:
$ ./hello
Getting help
The go command is a tool for managing Go source code. To see basic help, type:
$ go help
Sample outputs:
Go is a tool for managing Go source code. Usage: go command [arguments] The commands are: build compile packages and dependencies clean remove object files env print Go environment information fix run go tool fix on packages fmt run gofmt on package sources get download and install packages and dependencies install compile and install packages and dependencies list list packages run compile and run Go program test test packages tool run specified go tool version print Go version vet run go tool vet on packages Use "go help [command]" for more information about a command. Additional help topics: c calling between Go and C gopath GOPATH environment variable importpath import path syntax packages description of package lists testflag description of testing flags testfunc description of testing functions Use "go help [topic]" for more information about that topic.
To get more information on specific topic, type:
go help topicHere go help build go help build | less
References:
- See the Golang home page and documenation for more information.
🐧 5 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Hello,
Can I install MAC OS on my dell i7, 6GB RAM laptop?
Please give steps starting from downloading the DVD.
Thanks.
Legally you can not install it. But, google for Hackintosh for more info. HTH.
I need GO cross-compiling, so I recommend using homebrew to install GO compiler.
FYI, installing just Command Line Toolsis sufficient, don’t bother the fat ass Xcode.
Great tutorial. Thanks!
Excellent. Installed on my MacBook Air. Compiled and off to the races.
My first book is Caleb Dorsey’s An Introduction to Programming in Go,
available at Amazon.
My second Go book (arriving in November, also from Amazon) is Kernighan’s
book on Go (http://www.amazon.com/Programming-Language-Addison-Wesley-Professional-Computing/dp/0134190440)
If you want to talk about Go, exchange code, and the like, email me at smcracraft@icloud.com.
I would prefer to do all of it via a forum and github obviously.
Stuart