Golang Installation Guide

Golang Installation Guide

Hello Folks,

In this blog, we’ll learn about “The Most Promising Language” i.e. Golang and also how to install it. So, Let’s get started. 🙂

Golang is a programming language initially developed at Google in the year 2007 by Robert Griesemer, Rob Pike, and Ken Thompson and it’s very promising in fact that’s what JetBrains says. So JetBrains recently has done a poll with 7000 developers and this is the takeaways.

1_RJ3fNj1qaqVdBQbdEpE75Q.png

In the takeaways, JAVA is the most popular primary language as everyone knows about it and the JavaScript is a most used overall language and then Python the most studied language because it’s easy to learn and the most promising one is the Go language.

In fact, Hyperledger Fabric (Is modular blockchain framework which acts as a foundation for developing blockchain-based products) promotes Go language as their primary language. There are certain technologies like docker, Kubernetes they are developed in Go language.

Go programming language is a statically-typed (which means variables types are explicitly declared and thus are determined at compile time) language with syntax similar to that of C and C++. It provides garbage collection, type safety (means the type of the variable should be safe. e.g: can’t save or initialized a variable of string type with an integer), dynamic-typing capability, many advanced built-in types such as variable-length arrays and key-value maps. It also provides a rich standard library. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection (Reflection can be used for observing and modifying program execution at runtime). It’s fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.

A Go program can vary from 3 lines to millions of lines and it should also be written into one or more text files with extension “.go”; for example, hello.go

Now, if you want to do experiment with ‘Go’ they provide you with a playground. Yes, you don’t have to do setup just we do need set up for if you want to make a project but if you want to learn they have a playground.

1_SJAbgbrYnv_99jcxOERqOA.png

Here you can just click on this “ Open in Playground ” it will open a new tab with this.

1_lTms3Db7-yfGS19IrwbWBQ.png

Here you can write code or you can just simply click on “Run” what it will do it will send your script to the server for the compilation because you don’t have set up on your machine and then you will get the output. Hurray!! we run your first code without any setup.

1_Qzjp4e0gOU9pJjDnTZkbpA.png

Now, if you know the basics of programming may be Java, C, or C++ you will be understanding some of it. So basically in Java we to create packages same way we have a package here sometimes we have to import packages because if we use some external features or if you want to use any feature you need to import some packages that are what we are doing here. We are importing a package “fmt” which is for format and of course, if you want to run this code we have to write the main method or a function, so in “Go” we call them as functions and inside this, you just print “Hello World”.

Now In terms of comparison between different languages “Go” is faster it has an amazing feature and the best part it’s a new language. When I say new it’s not that new it’s been almost 10 years now but compared to another language it’s new it has some awesome features to work with and then the advantage would be if you learn go you will be probably among the few developers available in the market who knows “Go” and you’ll be one of them.

Installation of Golang

Now, if you want to download “Go” you do it from here you can use different IDE such as Eclipse, IntelliJ IDEA, GoLand or VS Code whichever favourite IDE you prefer you can use that, it just needs a “Go” compiler.

Here I will show you the installation of “Go” in VS Code.

Using the Go extension for Visual Studio Code, you get language features like IntelliSense, code navigation, symbol search, bracket matching, snippets, and many more that will help you in Golang development.

Firstly, you need to download the Golang and VS Code setup.

1_GzVVqUcudVSwAhckteQJRQ.png

If already downloaded, then install it on your machine like this in the image below 👇

1_emYrldwEpEW5rFkOgrSA0Q.png

Click Next to continue the installation process.

1_ZVCIb7la8D5a9t_HMOlONw.png

Checked the checkbox to accept the terms in the License Agreement.

1_qmDEHjRn_4oNZKl6iK-Gdw.png

Click on Install to proceed with the installation process.

1_LtyfKKK9WRc5URLl40IipQ.png

Wait until it completes.

1_7yEg7i4l3PFdGVeqa7i80A.png

Finally, your installation process of Go is completed.

Now, If you want to verify that the Go is installed in your machine or not, just open your cmd (command prompt) and write ‘go’. If you get an error like “go command not found” that means ‘go’ is not installed in your machine. If not, then you’re good to go.

1_YGV0JbrJNGpMO3dD1QCjkg.png

Now, we need to set the environment variables for ‘go’. So the steps are as follows:

Your workspace can be located wherever you like, but we’ll use C:\go-work in this example.

NOTE: GOPATH must not be the same path as your installation.

  • Create a folder at C:\go-work.
  • Right-click on “Start” and click on “Control Panel”, select “System and Security”, then click on “System”.
  • From the menu on the left, select the “Advanced systems settings”.

1_47DvFTZrLik7OxTGB3Qn5w.png

  • Click the “Environment Variables” button at the bottom.

1_e-yeq7WBq2IzHlupCSdVpQ.png

  • Click “New” from the “User variables” section.

1_7zqRdAL852T-bWxujGu1jQ.png

Select GOPATH from the User variable and click on ‘New’.

  • Type GOPATH into the “Variable name” field.
  • Type C:\go-work into the “Variable value” field.

1_RI6yQhR3Z-eMwO4LA9axvQ.png

  • Click Ok.

1_HelXNIm3-4TV5eM31-OVig.png

  • Then, click OK one more time.

Now, we have to open the folder go-work inside the VS Code through command prompt. Let’s see how can we do it.

1_svgnN30GLvvZqw6Vd6-vsA.png

The command "code ." will open VS Code Editor.

1_QfUl7P1XYHIl8l_FOhawng.png

To work with “Go” you need to install a plugin inside VS Code. Just by tapping to the Extension section in VS Code or use a shortcut key Shift + Ctrl + X.

1_tfN3ndys39AM_y-EJniBlw.png

Now, we just need to install this plugin.

1_I6NqAjESsJQRS2PCMFw3jA100.png

We have successfully installed the ‘go’ and now we are able to write our first program in ‘go’ using the VS Code.

Inside the go-work folder, we have created another folder named hello which contain one file named as "main.go".

rt.png

Yay!! We successfully run our first hello world program in GO.

Hope it helps.

Keep Learning, Thank you.