How to code in Go on Mac for Absolute Beginners using GoLand

Jyna M
5 min readJul 6, 2022

--

This guide is going to teach you how to setup Go and GoLand on your computer so you can write your first Go Program in minutes!

Photo by Pavel Herceg on Unsplash

Assumptions

Before we start, I’m going to assume you have never used Go and GoLand before and your computer is not setup either of these.

What is Go?

Go aka Golang is a coding language developed by Google. Specifically it is a compiled, statically typed language that is similar to C often used in backend programming due to its simple, reliable and concurrent abilities.

What is GoLand?

GoLand is a IDE (Integrated Development Environment) created by JetBrains to allow developers to code in Golang (Go) with ease and efficiency. In other words, it’s a place where you can code in Go.

Setup Go on your Computer

Download Go

1.Go to : https://go.dev/dl/

2. Download the package under the Apple Mac — get the latest version is fine

3. Double click on the package and it will start downloading

4. Warning: if it says the pkg file cannot be downloaded you probably downloaded the wrong go package for Mac, there are two. Make sure to download the package that is correct for your computer version

5. Follow the Download Wizard step by step until it is successfully downloaded

Check that Go has been Downloaded

  1. Go to your terminal by searching for ‘terminal’ in your computer
  2. Type in: ‘go version’
  3. You should see something like `go version go1.18.3 darwin/amd64` as a response. Which tells you that this computer has the go 1.18.3 version installed successfully

Setup GoLand IDE on Your Computer

Download GoLand

  1. Go to JetBrains website where GoLand is being downloaded
  2. Open the dmg file and you will get a prompt to drag the GoLand app to your applications folder.

3.Afterwards, you should be able to see the GoLand App in the applications folder

4. Double click the icon to open it up

5. It will prompt you to confirm the user agreement, go ahead and do that

6. Then it will prompt you to create a jet brains account so you can start your free trial, go ahead and follow instructions to get that done

Create and Run First Project on GoLand

Create New Project

  1. Open up GoLand > Create New Project

2. You will be asked to name the project and where you want it to be saved in your computer. Just set it to the default folder and click ‘Create’

Setup GOPATH

GOPATH is a variable that defines the root of your workspace. We’re going to use the default GOPATH setup that JetBrains suggests we do.

  1. Go to your “Users/<your user name>” location
  2. Create a folder called “/go”
  3. Inside the go folder, make 3 individual new folders: src, pkg, bin
  4. Go back to GoLand and on the top right of the header bar you will see GoLand click on that and follow this path: GoLand > Preferences > Go > GOPATH

5. Click on the ‘+’ symbols to add the path to the go folder you just created in step 2

6. Click ‘Apply’ and then ‘OK’ to finish

Setup GOROOT

  1. Top Right > GoLang > Preferences > Go > GOROOT
  2. Press the ‘+’ symbol to the right of the Go version and click ‘Download’

3. In the Download Prompt Box: Set to ‘/Users/<your username>/go’ and make sure that the go version is the correct one you downloaded

4. Go here for more information on this GOROOT and GOPATH

Run Your First Go Program

  1. Change the package name to ‘main’
  2. For all GoLang programs, there is a main function that triggers the program to run, it needs to be in a package named ‘main’ with a ‘main’ function
  3. As you can see in the screenshot below, I created a main function and had it print out a sentence
  4. You can run the program by pressing the green arrow that GoLand automatically generates next to your main function and the output of the printed line will show up the ‘run’ terminal of the IDE circled below.

Helpful Shortcuts on GoLand

  • Navigate to the Function Direction from another Function: Command + Hover over the function name + click
  • Search for words within a project, module or file : Command + Shift + F
  • Search based on file, symbol, action, or type names: Command + Shift + O (the letter)

Learn how to code in Go Resource:

And that is it! Congratulations, you have created your first Go Program using GoLand. I sense there will be more amazing programs you will create form here on out!

Feel free to leave comments on what amazing things you’ve managed to do once your Go Environment was setup!

--

--

Jyna M

Freelance Writer of Digital Marketing and Technology. Content Creator. Former Software Engineer.