How to Install Golang on MacOS?

How to Install Golang on MacOS?

Learn how to Install Golang on MacOS. We must have first-hand knowledge of What the Go Language is and what it actually does? Go is an open-source and statically typed programming language developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009. Golang programs can be written in any plain text editor like TextEdit, Sublime Text, or anything of that sort. One can also use an online IDE for writing Golang codes or can even install one on their system to make it more feasible to write these codes

Before, we start with the process of Installing Golang on our System. We must have first-hand knowledge of What the Go Language is and what it actually does? Go is an open-source and statically typed programming language developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009. It is also known as the Golang and it supports the procedural programming language. It was initially developed to improve programming productivity of the large codebases, multicore, and networked machines.

Golang programs can be written in any plain text editor like TextEdit, Sublime Text, or anything of that sort. One can also use an online IDE for writing Golang codes or can even install one on their system to make it more feasible to write these codes. Using an IDE makes it easier to write Golang codes because IDEs provide a lot of features like intuitive code editor, debugger, compiler, etc. In this article, we have covered the following topics:

  • Steps for Installing Golang on MacOS
  • Setting up the Go Workspace
  • Executing the First Golang program

Steps for Installing Golang on MacOS

Step 1: Checking if Go is installed or not. Before we begin with the installation of Go, it is good to check if it might be already installed on your system. To check if your device is preinstalled with Golang or not, just go to the Terminal and run the command:

go version

If Golang is already installed, it will generate a message with all the details of the Golang version available as shown below, otherwise, it will give an error.

Step 2: Before starting with the installation process, you need to download it. So for that, all versions of Go for MacOS are available on https://golang.org/dl/

Download the Golang according to your system architecture. Here, we have downloaded go1.13.1drawin-amd64.pkg for the system.

Step 3: After downloading process, install the package on your system:

Step 4: After completing the installation processes. Open a program known as Terminal(It is a command-line interface for macOS) to check whether Go install properly or not using the Golang version command. As shown in the below image, here it shows the version information of the Golang which means Go install successfully in your system.

Setting up the Go Workspace

After successfully installing Go on your system, now we are going to set up the Go workspace. Go workspace is a folder on your computer where all your go code will going to store.

Step 1: Creating a folder named as Go in documents(or wherever you want in your system) like as shown in the below image:

Step 2: Now tell the Go tools to where to find this folder. So for that first of all, you go to your home directory using the following command:

cd ~

After that set path of the folder using the following command:

echo "export GOPATH=/Users/anki/Documents/go" >> .bash_profile

Here, we are adding export GOPATH=/Users/anki/Documents/go to .bash_profile. The .bash_profile is a file that automatically loaded when you logged into your Mac account and it contains all the startup configurations and preferences for your command-line interface(CLI).

Step 3: Now check check that your .bash_profile conatins the following path using the following command:

cat .bash_profile

Step 4: Now we are going to check our go path using the following command. If you want to skip this step you can do that also.

echo $GOPATH

Creating first Golang program

Step 1: Download and install a text editor according to your choice. After installation, create a folder named go(or whatever name you want) in Documents(or wherever you want in your system). In this folder, create another folder named as source and in this source folder create another folder named as welcome. In this folder, all your go programs are going to be stored.

Step 2: Let’s create first go program. Open the text editor and write go program as shown below:

Step 3: After creating a go program save that program with extension .go.

Step 4: Now open terminal to run your first go program.

Step 5: Change the directory in which your program is stored.

Step 6: After changing directory, run the go program using the following command:

go run name_of_the_program.go

go golang macos

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Go Tutorial (Golang) 18 - tags in Golang | How To Use Struct Tags in Go

Go struct tags are annotations that are shown after the type in a Go struct declaration. Golang tag for a field allows us to attach meta-information to the field which we can acquire using reflection

Why Golang (Go) so Fast?

Go is praised by everyone for achieving extremely high concurrent performance, but Why? In this Golang (Go) tutorial, I’ll introduce how the Go program to achieve extremely high concurrent performance, and its internal scheduler implementation architecture (G-P-M model). I’ll also explain how Go can make full use of computing resources, and how the Go scheduler deals with threads step by step

Secure HTTPS servers in Go

In this article, we are going to look at some of the basic APIs of the http package to create and initialize HTTPS servers in Go

Introduction to Golang | What is Go | Why Use Go

Golang is the procedural and statically typed programming language having syntax similar to C programming language. Often, it is termed as Go Programming Language. It provides the strong standard library, garbage collection, and dynamic-typing capability.

Go Tutorial (Golang) - Structures in Go

Structs are the way to create user-defined types in Golang. One of the most useful data structures in computer science is the hash table. Many hash table implementations exist with varying properties, but in general they offer fast lookups, adds, and deletes. Go provides a built-in map type that implements a hash table.