Mac OS X: Install Go Programming Language

How do I install Go language on Apple Mac OS X? How to setup GO lanuage on Mac OS X? How do I install Go language version 1.2+ on OS X?

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

Fig.01: Installing Xcode on OS X

Fig.01: Installing Xcode on OS X

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:

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:

GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"

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.


	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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • visitor1 Dec 3, 2013 @ 0:06


    Can I install MAC OS on my dell i7, 6GB RAM laptop?
    Please give steps starting from downloading the DVD.


    • 🐧 nixCraft Dec 4, 2013 @ 11:31

      Legally you can not install it. But, google for Hackintosh for more info. HTH.

  • Meow Dec 7, 2013 @ 14:22

    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.

  • Derek Jul 8, 2015 @ 20:22

    Great tutorial. Thanks!

  • Stuart Cracraft Jul 16, 2015 @ 4:42

    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 (

    If you want to talk about Go, exchange code, and the like, email me at

    I would prefer to do all of it via a forum and github obviously.


Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum