AppDividend
Latest Code Tutorials

How To Install Go On Mac | Go Programming Language

0

How To Install Go On Mac | Go Programming Language is today’s topic. In this tutorial, you set up your Go environment. Go provides binary distributions for Mac OS X, Windows, and Linux. If you are using a different OS, you can download the Go source code and install from source.

How To Install Go On Mac

Download the latest version of Go for your platform here: https://golang.org/dl/.

Follow the instructions for your platform to install the Go tools: https://golang.org/doc/install#install. It is recommended to use the default installation settings.

On Mac OS X and Linux, by default Go is installed to directory /usr/local/go, and the GOROOT environment variable is set to /usr/local/go/bin.

You may need to restart any open Terminal sessions for the change to take effect.

Also, we need to install the VSCode, because there are some tools which we will install inside VSCode which will help us during the developing Go project.

Now, Create a go file named hello.go and add the following code.

/* hello.go */

package main

import "fmt"

func main() {
   fmt.Printf("Welcome to GO AppDividend")
}

Okay, now you can run the file using two ways.

First, you can compile the file using the following command.

go build

It will create an executable file with the same file name. So, if your filename is hello.go, then it will create hello file. On MAC, it is just hello file, in windows, it is a hello.exe file.

Now, run the executable file on Mac using the following command.

./hello

It will give the output in the terminal.

 

How To Install Go On Mac

There is also another way in which you get the direct output.

Type the following command in your terminal.

go run hello.go

 

Go Programming Language

In Visual Studio Code, our project looks like below.

 

How To Install Go On Mac | Go Programming Language

Finally, How To Install Go On Mac | Go Programming Language Tutorial is over.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.