How to Install Golang on Mac

Follow these steps to install Golang on Mac:

  1. Download the latest version of Go for your platform here: go on mac
  2. Follow the instructions for your platform to install the Go tools: It is recommended to use the default installation settings.
  3. On Mac OS X and Linux, Go is default installed to directory /usr/local/go, and the GOROOT environment variable is set to /usr/local/go/bin.Install Golang on Mac
  4. You may need to restart any open Terminal sessions for the change to take effect.
  5. Also, we need to install the VSCode, because some tools we will install inside VSCode will help us during the Golang project development.

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

package main

import "fmt"

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

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; if your filename is hello.go, then it will create a hello file. On MAC, it is just a hello file; in Windows, it is a hello.exe file.

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



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 the one below.

How To Install Go On Mac | Go Programming Language

Install Golang Tools On Mac

If upgrading from an older version of Go, you must first remove the existing version.

Linux, macOS, and FreeBSD tarballs

Download the archive and extract it into /usr/local, creating a Go tree in /usr/local/go. For example:

tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

Choose the archive file appropriate for your installation. For instance, if you install Go version 1.2.1 for 64-bit x86 on Linux, the archive you want is called. go1.2.1.linux-amd64.tar.gz.

(Typically, these commands must be run as root or through sudo.)

Add /usr/local/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile (for a system-wide installation) or $HOME/.profile:

export PATH=$PATH:/usr/local/go/bin

Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile.

That’s it.

Leave a Comment

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