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!
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
- Go to your terminal by searching for ‘terminal’ in your computer
- Type in: ‘go version’
- 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
- Go to JetBrains website where GoLand is being downloaded
- 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
- 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.
- Go to your “Users/<your user name>” location
- Create a folder called “/go”
- Inside the go folder, make 3 individual new folders: src, pkg, bin
- 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
- Top Right > GoLang > Preferences > Go > GOROOT
- 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
- Change the package name to ‘main’
- 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
- As you can see in the screenshot below, I created a main function and had it print out a sentence
- 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!