What the $GOPATH is about
Tags: golanguage, beginners, go
Published: 2020-04-11 10:24:09

---
title: What the $GOPATH is about
published: true
date: 2020-04-09 13:50:34 UTC
tags: Go Language,beginner,golang,go
canonical_url: https://fabcodes.hashnode.dev/what-the-dollargopath-is-about-ck8stjzhh004y07s129623r3v
---

## Introduction

I just recently started learning the GO programming language. While I have realized that keeping notes of what I am learning along the way is crucial to the learning process, I also decided to as well share some of my notes in the form of short articles revolving around everything I have learnt.

I almost skipped knowing what the `$GOPATH` is about all together as it wasn't discussed properly in the first resource I tried learning GO with. But from what I have gathered, I realize it is important to understand what the `$GOPATH` is and understand how it works.


## What is $GOPATH?

I'll be answering this in a bullet point format to make it easier to digest. Here are some of the points I gathered:

- The `$GOPATH` is an environment variable. It shows a location to a physical directory on a machine which has GO set up.

- The `$GOPATH` directory is automatically created under the `users` folder when the Visual Studio Code [GO extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go) is installed so we do not need to create it.

- By default, GO assumes that the folder `$GOPATH` shows is in your `users` folder. So we do not need to set it.

- To know what your `$GOPATH` is, use the command below in your terminal:
```
$ go env GOPATH
```
It is usually in the form `Users/{user}/go`

- The directory `$GOPATH` points to is also referred to as a **Workspace**. It also shows GO tools where it can find GO source code files and other related stuffs like compiled packages, executable binaries and so on. By convention, every GO project uses this folder.

- Inside this directory are three folders: `bin`, `pkg`, and `src`. The `src` folder contains GO source-code files and this is where we keep our GO projects.

- When we download a GO project, it is stored under the `$GOPATH`.

- An executable GO program needs its own directory which we create under the `$GOPATH/src` folder. For example:
```
$GOPATH/src/helloworld/main.go
```

- If you have a GitHub account, it is better to put your project in a `github.com` folder under the `src` directory i.e.
```
$GOPATH/src/github.com/{your-username}/helloworld/main.go
```

-  Since we will be creating our projects under the `$GOPATH/src` folder, to open up the folder in VS Code using the terminal, if you're on MAC or have git bash installed on Windows, type:
```
$ code ~/go/src
```

## Conclusion
Looking back, I realize how vital understanding what the `$GOPATH` is as a GO developer and how important its concept is in developing GO programs and packages. It is in fact a convention in the GO community and I would definitely urge anyone new to the language to endeavour to understand what it is.

## Other Articles 📖
- [The Classic Hello World Program in GO](https://fabcodes.hashnode.dev/the-classic-hello-world-program-in-go-ck8syp9cm00380fs12jyrolnh)
- [An Introduction to GO Packages](https://fabcodes.hashnode.dev/an-introduction-to-go-packages-ck8uq9xq700ablcs1rmd4na8w)

#### Code Samples - https://github.com/Fakorede/Learning-Golang