This article covers brief steps of how to install, setup necessary tools which could help you to write & run your 1st Go Lang program, in your Linux machine.
Download & Installing Go
- Browse to https://golang.org/dl/ and click the download link of Go Lang’s Linux Binary

- Once the download process is completed, open your terminal window, go to the directory where contains the downloaded go lang’s binary file (e.g.
~/Downloads)

- Run
tar -xvfcommand to extract extract the content of go lang binary file.

tar -xvf command for extracting go lang binary file.- Move the extracted folder
gointo/optfolder.

- Go to home directory then edit
.profilefile in there. In case you have not created it yet, create a new one. Open the file in text editor such as vim, and write down a line for declaring a new environment variableGOROOTwhich points to the location of our moved go binary files, the/opt/godirectory. Then, add a line which export & concat the$GOROOT/binpath withPATHvariable so that we could rungoin any directories.

- Save the changes in
.profilefile then runsource .profilecommand in terminal to get our new changes take effect immediately in our environment.By the next time you login or booting into your linux box using your current login account, you should be able to rungocommand from any directories.

Setup your 1st Go Lang workspace
Workspace in Go Lang, is a directory which contains source code of our go lang application & library projects, 3rd party go dependencies & binary files of our compiled go lang projects. Below are steps of how to create it:
- Create a new directory somewhere in your home directory (e.g. ~/projects/golang). This directory will be the root of our golang’s workspace directory. Within the directory, create 3 new sub directories with these following names:
bin,pkg, and src

- Going into
srcfolder, we’ll create a new subdirectory which represents our source control provider such asgithub.com. Then, we are going to the created new subdirectory, and create another new subdirectory. We name the new subdirectory same as our source control provider account’s name (e.g. WendySanarwanto).

- Go back to home directory, edit
.profilefile again in a text editor. Add a new entry which exportGOPATHenvironment variable. Ensure that theGOPATHvariable points to the path of our workspace directory (e.g.~/Documents/projects/golang). Save changes and re-runsource .profilecommand to force the changes taking effect in your environment immediately.

Creating your 1st “Hello World” Go Lang project
From here, we have already created our initial go lang workspace. Now, we are ready to create our 1st “Hello World” Go Lang project.
- Go to the workspace’s source code directory then create a new directory (e.g.
~/Documents/projects/golang/src/github.com/name/hello-golang) - Create a new
.gofile (e.g.hello.go). Open the file using code editor such as Visual Studio Code. - Inside opened the blank
.gofile, we’ll write our 1sthello worldin go lang as follow:

- We’ll go back to terminal, and run
go install github.com/username/hello-golangcommand to compile the program. The compiled binary file will be put under$GOPATH/bindirectory.

- Since we have exported the
$GOPATH/binas a part of$PATHvariable, we should be able to run the program through runninghello-golangcommand (name of your compiled go lang program).

Conclusion
At this point, we have already setup Go Lang workspace in our linux box. The workspace is a single location of where we will put files , directories of our current & future go lang source code projects, dependencies & compiled projects inside.
We also has setup GOPATH & GOROOT environment variables, integrate them with the PATH variable. This would make our efforts easier when we want to go into the workspace’s location, execute compiled binaries or just running go command from any directories.