Day 20: Hello Go — Quickstart Guide

Harini Janakiraman
Jun 2, 2016 · 2 min read

#100DaysOfCode

Project (30 mins): Quick and easy installation of “Go” and using it for creating your very first Go app.

All the code for this project can be found on my github

Step 1: Install

Use this link to install Go lang on your machine. Check by running go on the terminal which should give out usage like below.

Image for post
Image for post

Step 2: Setup Workspace

Go commands all rely on one important environment variable called $GOPATH which points to the Go workspace (note this is different from $GOROOT which tells where Go is installed). Set it up as follows in Unix-like systems;

export GOPATH=/Users/Harini/Go

Step 3: Create simple app

  • In $GOPATH, create three folders: src, pkg, bin
  • Create a package directory called “mymath” in src dir and add a “sqrt.go” file to it as follows:
  • Compile package using the following command which will generate “mymath.a” file in pkg directory.
cd $GOPATH/src/
go install mymath
  • Now create an app directory called “mathapp inside src directory. Add a file called “main.go” to it with the following code:

Step 4: Build and Run

Build the go file to create an executable file called “mathapp” inside bin directory using the following command:

cd $GOPATH/src/mathapp
go install

Now running the executable mathapp should show you the following:

./mathapp
Hello world. Sqrt(2) = 1.414213562373095

Day 20 of #100DaysOfCode DONE

If you enjoyed this, please click 👏 so that others can enjoy it as well. Follow me on Twitter @HariniLabs to get the latest updates or just to say Hi :)

PS: I curate a bi-weekly #WomenInTech newsletter for a dose of inspiration from the world of tech and yes men can signup too! Get it here :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store