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:
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:
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.
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:
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:
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.
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
- How to Install Go on Windows?
- How to convert a slice of bytes in uppercase in Golang?
- Golang program that uses fallthrough keyword
- math.Lgamma() Function in Golang with Examples
- math.Float64bits() Function in Golang With Examples
- How to check equality of slices of bytes in Golang?
- atomic.AddInt64() Function in Golang With Examples
- atomic.StoreInt64() Function in Golang With Examples
- reflect.FieldByIndex() Function in Golang with Examples
- string.Contains Function in Golang with Examples
- bits.Sub() Function in Golang with Examples
- How to convert a slice of bytes in lowercase in Golang?
- io.PipeWriter.CloseWithError() Function in Golang with Examples
- Import in GoLang
- time.Round() Function in Golang With Examples
- How to add a method to struct type in Golang?
- Converting a string variable into Boolean, Integer or Float type in Golang
- Check if the given slice is sorted in Golang
- How to compare times in Golang?
- reflect.AppendSlice() Function in Golang with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.