Install Golang on Win, MacOS and Linux

Learn via video courses
Topics Covered

Golang, also known as Go, is an open-source, statically typed programming language developed by Google. Its syntax resembles C, offering memory safety and garbage collection. Ideal for building simple, reliable, and efficient software, Go supports procedural programming and is notable for concurrent programming capabilities. To write Golang programs, simple text editors like Notepad or IDEs offer enhanced features like a debugger and compiler. Installing Go on your system is essential before writing and running Go programs like 'Hello World'. This article provides a step-by-step guide to installing and configuring the Go compiler on Windows, Linux, and MacOS, enabling you to start programming efficiently in Go.

Install Golang on Windows

To avoid having to remove Go and spend many hours debugging any installation-related difficulties, make sure to complete these instructions in their completeness and in the right sequence (as specified).

As a first step, let's examine the Windows installation of Go.

Install using MSI installer and git

  • Go often uses open source repositories (free!), so first install the git package here.

  • Go to the Go installation website here.

  • Download and install the latest 64-bit Go Set for your Microsoft Windows operating system. Follow the Go installer instructions.

First, accept the license agreement. Then click next.

To start the installation, click Install. Windows will request administrative consent. Simply accept it.

The installation of Golang was successful. We must now verify that everything has been set up correctly. From the command prompt or any other terminal, we may verify that.

Check the GoLang version installed

  • After entering the go version the output looks like this:

Verify that GOPATH is Set Correctly.

  • Verify your Go binaries first: Go to the Control Panel on your computer, select System and Security > System >Advanced system settings, and then click the Advanced tab in the left-hand pane. Next, select Environmental Variables from the bottom-right menu.

  • Make the GOPATH variable, then refer to your freshly made Go workspace. Afterward, select Environmental Variables from the System menu in your Control Panel. Click New under System Variables after that.

Put "GOPATH" next to Variable Name, then add “C:\Projects\Go” after Variable Value.

It can be changed to any folder of your choice.

  • To ensure that your path has been successfully specified, enter “echo %GOPATH%” on the command line.
  • Simply select Edit, then type the path or browse the folder to modify GOPATH.

Congratulations! Go has been successfully installed on your Windows system.

Install Golang on Linux

First, Update your system using these commands:

After updating, use your browser and proceed to the go downloads page as instructed in the following resource:

Find the download link for the go version you want, then copy it.

Open a terminal and type the following command:

The above lines should set up the wget tool and enable you to download the go compiler's tarball bundle.

After downloading, use the LS command to see if the file is there as follows,

The archive's contents must then be extracted in the following step. The command can be used as follows:

Setting the travel course is the next stage. This enables access to the go executable from locations other than the primary go directory or without using an absolute path.

We can transfer the go directory to a more relevant directory for our convenience.

The above command should transfer the downloaded go directory to the /usr/local directory.

We can update the .profile file in the home directory as described in the commands below to set the path to the go binary:

Add the following line to the file:

Update it:

Finally, execute the following command to confirm that go was successfully installed:

  1. Ubuntu / Debian Linux Install the necessary software to execute Go applications.
  1. CentOS 7 / Redhat Linux

If you use Redhat or CentOS, you can use yum to install go

Finally, verify the installed version of Golang.

Manual installation

For manual installation, you can refer to here.

Install Golang on Mac OS

The easiest way to install Go on Mac OS is using homebrew

Using the macOS Package Installer Download the latest Go package file (.pkg) from the official Go download page. Follow the installation instructions after opening the package. Go is automatically installed in /usr/local/go.

Second Method

Step 1: First, download Golang

Visit to download the most recent Go release. The Apple macOS download link will appear. Go 1.19's current version only supports 64-bit versions of macOS 10.10 or later.

As an alternative, the curl command-line tool can be used to download Go 1.19.

Step 2: Install Go on macOS

On your macOS computer, the Go package has been downloaded. Simply double-click the downloaded file to launch the installation process to install it.

The installation can be started by running the command listed below for command-line users.

A wizard for installation will launch. Complete the installation by referring to the on-screen instructions.

Step 3: Setup Workspace Go To set environment variables, edit the ~/.bash_profile or ~/.profile file (or its equivalent). Three environment variables—GOROOT, GOPATH, and PATH—are frequently required to be configured.

Set the GOROOT, which designates the installation directory for Golang.

Then, specify the location of your work directory in the GOPATH environment variable. For instance, the directory for my project is ~/Projects/Proj1.

Now modify the PATH environment variable to provide system-wide access to the go binary.

Step 4: Install the Go Dependency Management Tool

The govendor is a tool for effectively managing the dependencies for Go applications. If you want to put something on your PC, you should think about it.

Go packages for your application are now simple to install and manage.

Step 5: Check Go Version

Installation From Source (UNIX/Linux/Mac OS X)

UNIX, Linux, Mac OS X, and the FreeBSD system utilising the source code installation method

  1. Download the go1.11.linux-amd64.tar.gz source package.
  2. Extract the source package from the download into the /usr/local directory.
  1. add the /usr/local/go/bin listing to the PATH surroundings variable:

Congratulations! YaY..!! 🥳 Welcome to the Go Lang universe. Now that the installation is complete, you are prepared to demonstrate your programming prowess.

Conclusion

  • In this article, you got familiar with the installation of golang in different OS such as Linux, Windows and Mac Os.
  • Go (Golang) can be installed on a Linux computer in two different methods. It is necessary to get the official Golang Installers for Linux systems, as displayed below. On your CentOS 7 or RHEL 7 computer or Ubuntu, you may install Golang using this extra method.
  • Using homebrew is the fastest way to install Go on Mac OS.
  • For windows we can directly download the msi file and easily setup in our system.