Monday, August 19, 2019

Set Up Go Programming Environment for Mac OS X

To start programming with Go programming language, we need to install it, there are many ways to install go, for Mac OS user there is an easy way to install it, using Homebrew.

But, we need to install Xcode first, after that we can type the following command to install Golang using Homebrew:

$ brew install golang
We can verify the installation using this command:

$ go version
Set Up Go Workspace

We need to setup our workspace, let start by creating folders:

$ mkdir -p $HOME/go/{bin,src,pkg}
After that, update .bash_profile with the following exports:

export GOPATH=$HOME/go

export PATH=$PATH:$GOPATH/bin

Reload bash profile by executing:

$ . ~/.bash_profile

Create Hello World Program

Let start writing go program, just to test our installation and setup by writing hello world program:

create hello.go any where, and type the following program:

package main

import "fmt"

func main() {
  fmt.Println("Hello World")

to run the hello world program, type:

$ go run hello.go

And this program will output:

Hello World

No comments:

Post a Comment