Contents

Step-by-Step installation of Golang on Mac OS


Step by Step installation of Golang on Mac OS.


There are various ways to download and install Golang on the Mac OS but I am going to explain the easiest one.

Saving some time to learn Golang. 😉


Step 1. Download Golang from Official website


Navigate to https://golang.org/dl/ and download Golang(.pkg) package.

/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_25.jpg

Step 2. Open the package and follow installation steps


/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_4.jpg /step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_6.jpg

Step 3. Verify Installation


Once the installation is completed. Open terminal and type > go version ↵ and you should be able to see some information like > go version go1.14.6 darwin/amd64

/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_24.jpg

Step 4: Verify Environment Variables


Use the command > go env ↵ to check Golang env variables.

/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_10.jpg

Step 5: Download and Install VS Code


Following IDE supports Golang but for this tutorial, I am going to use VS Code.

  1. Visual Studio Code (VS Code is free and built on open source)
  2. IntelliJ IDEA
  3. Vim
  4. Sublime Text
  5. Eclipse
  6. Atom
  7. GoLand
  8. LiteIDE

Download VS Code from https://code.visualstudio.com/download and follow the procedure to install.

Step 6. Configure VS Code for Go


Once VS Code is installed, Go to Code > Preference > Extension or press ⌘⇧X Search Go extension in marketplace and install.

/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_17.jpg

Step 7. Project folder setup


There is a basic layout available for Golang application projects. It’s not an official standard defined by the core Go, dev team; however, it is a set of common historical and emerging project layout patterns in the Go ecosystem. Some of these patterns are more popular than others.

Refer https://golang.org/doc/ for more information on the Go Project Layout.

You can create a folder structure manually or you can just download any template of go project from the GitHub.

In this tutorial, we will use https://github.com/go-training/helloworld

Use command > go get github.com/go-training/helloworld ↵ to download helloworld template.

/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_11.jpg

A project workspace would be created once the template is downloaded. You can see the PATH of workspace in > go env or you can navigate to /Users/<<user_name>>/go folder.

/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_13.jpg

Step 8. Install support Go packages


The quick and easiest way to install Golang packages is from VS Code. To install, Open helloworld template in VS Code.

Navigate to main.go and start typing something. As soon as you type, a popup will be displayed as shown below,

/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_18.jpg

Few additional packages are required for Goland while using VS Code so click on “Install All” and install all packages.

The below message will be displayed in the terminal once the installation is completed.

/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_20.jpg

Step 9. Finally, Run and Test Go Program


  • To run go code, use > go run <<file_name.go>> ↵
  • To test go code, use > go test ↵

/step-by-step-installation-of-golang-on-mac/golang_installation_on_mac_23.jpg


Hope you liked this quick tutorial to install Golang with VS Code on Mac. Happy Go ❤️ Programming!