Getting started with Golang

golang
Reading Time: 3 minutes

Hello Readers! You all must have heard about Golang. So, In this blog we will see how you can set up golang in your system and after that we will see a simple demo with getting started with golang.

Here are the 4 easiest steps to get Golang up and running in your linux machine. So, let’s get started.

Step 1: First step is to download the Linux tar.gz package from Golang website. So, download the latest, and stable binary release from its website i.e : https://golang.org/dl/

image

Step 2: Next step is to unzip the tar.gz package. After that move it to the /usr/local directory.

image

Step 3: Next step is to add the its binary to the $PATH environment variable. You have to open your .bashrc file and paste this line there.

terminal

Step 4: Now In the same file add a variable called $GOPATH and point to where your Golang apps are going to live. After this, reload your .bashrc file.

terminal

Step 5: Test its version and Confirm that the command prints the installed version of Go.

version

So, Now we are all set for getting started with it.

Hello, World! is the first basic program in any programming language. Let’s write the first program in the Golang using the following steps:

First step is to open a command prompt and cd to your home directory. I will create a hello directory for my first Go source code.

hello

Move to this directory.

Secondly you have to enable dependency tracking for your code.

Run the following command for this.

hello

File will be created by this.

go.mod

Create a file hello.go and paste the following code here.

hello.go

Now, you can run the code to see the output.

gorun

Use the following command to get a list of the others:

go help

Conclusion

In this blog we have seen how to setup golang in your ubuntu and how to get started with it. We have also seen here a simple demo of hello world. Thanks for being with me till the end. If you find this blog helpful do share with your friends.

HAPPY LEARNING!

knoldus

Written by 

Naincy Kumari is a DevOps Consultant at Knoldus Inc. She is always ready to learn new technologies and tools. She loves painting and dancing.