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 2. Open the package and follow installation steps
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 4: Verify Environment Variables
Use the command > go env ↵
to check Golang env variables.
Step 5: Download and Install VS Code
Following IDE supports Golang but for this tutorial, I am going to use VS Code.
- Visual Studio Code (VS Code is free and built on open source)
- IntelliJ IDEA
- Vim
- Sublime Text
- Eclipse
- Atom
- GoLand
- 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 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.
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 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,
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 9. Finally, Run and Test Go Program
- To run go code, use
> go run <<file_name.go>> ↵
- To test go code, use
> go test ↵