How to Install Go on MacOS
MacOS is an operating system for desktop computers and tablets developed by Apple specifically for its devices. It is initially pre-installed on all Apple devices, specifically the Apple Macintosh or Mac for short.
Unlike Linux, macOS is a proprietary operating system, which, of course, brings certain peculiarities in installing various development tools on it. To see more details about it, check our instruction on how to deploy cloud server on MacOS.
In this article, we will take a detailed look at how to install Go on a macOS computer.
Google created the open source programming language Golang, or just Go, to build microservice-based systems. You may find other Go frameworks, like Beego and Gin, on our app platform.
To ensure the stability of your computer and the Go compiler, we recommend using the latest version of macOS.

Installing GO is a Simple Process
1. Uninstall old Golang versions Copy link
Check if Golang is already installed
Before you start installing Golang, first check if it is installed on your system already. A simple way to do this is to run a command that outputs the Golang version:
go versionIf Go is indeed installed, you will see a message in the console terminal displaying the language version and the operating system's name. Something like this:
go version go1.21.3 darwin/amd64Uninstall Golang
If Go is present on your system, you need to uninstall it to avoid possible installation conflicts.
MacOS stores files from the Golang package in a predetermined location:
-
The
/usr/local/godirectory. This is where Golang itself is placed. -
The
/etc/paths.d/gofile. Golang environment variables are specified here.
So, to uninstall Golang, you need to clear the above directories:
rm -rf /usr/local/gorm -rf /etc/paths.d/goThe rm command deletes a directory or a file, while the -rf flag indicates a recursive-forced type of deletion.
-
rstands for recursive and is used to delete the specified folder, all its subfolders, subfolders of subfolders, etc. -
fstands for force so no external states or variables can prevent the deletion from occurring
Great! Golang is now removed from your computer. This means we can move on to downloading the Golang package for macOS and then installing it.
2. Download Golang Copy link
The Go language archive can be downloaded to your computer in two different ways. One is highly automated, while the other more manual. Let's examine both.
Manual download
The official Golang website has a special page with links to download the latest version of Go.
Once you open it, you will see several buttons leading to the latest language version for a particular platform. We are interested in the Apple operating system.
At the moment of writing this article, there are two versions of the language for MacOS. One is for the new Apple ARM64 processor architecture, and the other is for the classic Intel 65-bit architecture.
You should choose the one that suits your device. The latest Mac models have ARM64 processors.
Clicking on the link will start downloading the archive file named go1.21.3.darwin-amd64.pkg, or a later version.
Download via console
An alternative to downloading manually is using the command line.
MacOS has a special curl tool included in the operating system.
So we can use the curl utility with the exact URL where the Golang archive file is available:
curl -o golang.pkg https://dl.google.com/go/go1.21.3.darwin-amd64.pkgThis command uses a special flag -o (--output), which ensures that the data received through the curl request is written to the golang.pkg file.
Note that the URL contains the exact name of the file we want to download and the Golang version.
When the curl command is finished, we will have a golang.pkg file containing the Golang language package. Then we just need to install it.
3. Install the Go package Copy link
As with the download, installation is also available in two ways: through the GUI or the command line interface.
Installing via GUI
To install Go on macOs, simply run the downloaded package.
After the automatic installation is done, you will get a success message confirming that the software is installed.
Installing via command line
If you prefer working with the terminal, run the following command:
sudo open golang.pkgAfter that, follow to the terminal's instructions until a popup confirming the installation's success displays.
4. Set environment variables Copy link
After installation, we must tell the system where to find the Golang compiler when the console terminal receives the command to compile and run the application.
First, let's navigate to the home directory using the following command:
cd ~Now add the locations of the Golang components to .bash_profile. This file is automatically loaded when you log in to your macOS account and contains all the startup configurations for the command line interface.
Add environment variables to the end of the file, either manually or via the echo command:
echo "export GOROOT=/usr/local/go" >> .bash_profile
echo "export GOPATH=$HOME/Documents/go" >> .bash_profile
echo "export PATH=$GOPATH/bin:$GOROOT/bin:$PATH" >> .bash_profileThe >> operator indicates that the text in quotes after echo will be written to the .bash_profile file.
The GOROOT variable points to the directory where the Go compiler is installed. GOPATH contains the address of the Go working directory. And PATH helps the command line to find binary files during source compilation.
5. Check the installation Copy link
To verify that Golang has been successfully installed on macOS, you need to restart the command line terminal and query the Go version:
go versionIf the installation was done correctly, the console will display a message:
go version go1.21.3 darwin/amd646. Launch a test application Copy link
In this article we won't go into the details of Golang syntax and peculiarities of programming in this language. We will just write, compile, and run a simple program with trivial output to the console to make sure that the installed compiler works.
Let's create a new file in our home directory using the nano editor:
nano main.goThen fill it with the following contents:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!") // CONCLUSION: Hello, World!
}
To exit nano, press "CTRL+X". When prompted to save the file, press "Y", then "ENTER".
Now we can compile and run our program with just one command:
go run main.goThere is also another command that builds the application source code into a complete executable file that can be distributed and deployed to other local machines:
go buildIf you don't specify the name of the go file as an argument, the command will compile the file with the standard name main.go.
For example, if the file containing our program were named test.go, the build command would look like this:
go build test.goDuring build, the Go compiler will include all the .go files involved in the final "build", adding the auxiliary code needed to run the application on any computer with the same system architecture.
Building to an executable file allows programs to run on other computers regardless of whether the Golang compiler itself is directly installed on them.

Visualization of Go Installation on MacOS
Conclusion Copy link
Despite being a proprietary operating system, macOS allows you to install tools from third-party companies and developers (in our case, Google), including open-source solutions.
In this article, we have looked at the standard way of installing the Golang compiler on macOS, which includes a few basic steps:
-
Checking for older versions
-
Uninstalling the old versions if they exist
-
Downloading the package from the official website (manually or automatically)
-
Installing the downloaded package (via GUI or terminal)
-
Adding environment variables
-
Checking if the installation is correct
-
Compiling and running a simple code
With these steps, we installed Go on macOS and ran our first program using fairly simple commands. For further study of the language and deeper familiarization with its syntax, we recommend checking the documentation on the official Golang website.
Also, Hostman offers various VPS Servers for you to host on Mac by low price!
Frequently Asked Questions (FAQ) Copy link
Can I install Go using Brew? Copy link
Yes, this is the easiest method for macOS users. Simply open your terminal and run: brew install go Homebrew will handle the download, installation, and path configuration automatically.
How to check if Go is installed on Mac? Copy link
Open your terminal and type go version. If it is installed correctly, you will see output similar to:
go version go1.21.5 darwin/amd64
Where does Go install on macOS? Copy link
-
Official Installer:
Installs to /usr/local/go. -
Homebrew: Installs to /opt/homebrew/Cellar/go (on Apple Silicon) or /usr/local/Cellar/go (on Intel Macs), with symlinks placed in your standard path.
How to apt install Go? Copy link
You cannot use apt on macOS, as it is the package manager for Debian/Ubuntu Linux. On macOS, the equivalent command is brew install go.
Is Go faster than Java? Copy link
Generally, yes, but it depends on the metric.
-
Startup & Memory: Go is significantly faster at startup and uses much less memory because it compiles directly to machine code (AOT).
-
Raw Throughput: Java's JIT (Just-In-Time) compiler is highly optimized for long-running processes, often making it competitive or equal to Go in raw calculation speed over time.
Do I need to set GOPATH and GOROOT? Copy link
In modern Go (versions 1.11+ using Go Modules), manually setting GOROOTand GOPATH is rarely necessary for standard development. The default settings usually work out of the box.