So, you have done your research and made a decision to go ahead with learning Golang. Great! In order to get started, you need to install Go in your system. You can take the help of Golang development services. However, if you give this blog a thorough read, then you can carry out the setup process yourself.
So, let us jump right into the process.
Now, to do the setup, you require two pieces of software. These are:
- A compiler
- An IDE (Integrated Development Environment)
Why an IDE?
An IDE is essential for any programming language, be it Golang, Java or Python. You can carry out programming on a normal editor. However, when you will be dealing with complex projects, it will involve much more than coding. You also have to debug, get proper output, and create different files.
When it comes to Golang, you have various options at hand. You can use Eclipse, Atom, Goland, LiteIDE, etc. However, in this blog, we will consider the most popular VS Code.
How to Install the Golang Compiler?
In order to install the Golang compiler, you have to abide by the steps mentioned below.
- You have to go on Google and type ‘Download Go’. You have to click on the official website, i.e, golang.org.
- When you open the page, you will get to see Featured Downloads. Here, you should choose the one for Microsoft Windows. You will get to see the latest version, go 1.19.windows-amd64.msi. The file size is 136 MB.
- As you click on the Windows Installer, all you have to do is click on Next and accept the terms and agreement. Now, here you have to make a decision as to which path you should choose. So, it's better to keep it simple and stick with ‘C:\Go\’, i.e. the C drive on your system.
- Finally, you have to click on ‘Install’. Once the installation process is complete, you have to click on ‘Finish’.
Now that the compiler has been installed, we have to verify it. For this, you should go through the steps below.
- You have to open the Command Prompt, and type ‘go’. Once you do so, you will be displayed the Usage and the list of commands. You will also get to see additional help topics. If it was not properly installed, then you would have received an error. It will say ‘go is not a recognized command.’ If by any chance, you are unable to resolve the issue, then you should not hesitate in availing Golang development services from professional experts.
How to Install the VS Code?
If you wish to download VS Code, you have to follow the steps highlighted below.
- Again, you have to type on Google ‘Download Visual Studio Code’. It will provide you with the download link, as the first link itself.
- Once you click on the link, you will be greeted with download options for various OS. But, you have to select Windows. And depending on the architecture, you have to select 64-bit or 32-bit.
- After you click on it, the VS Code will be installed on your machine. You have to click on the Application in order to initiate the installation process.
- Similar to the installation process of the compiler, you have to accept the agreement. Then you have to keep on clicking on ‘Next’. If you wish to create a desktop icon, you can click on it.
- Finally, you have to click on ‘Install’. Once the installation is fully finished, you have to click on ‘Finish’ to exit the user setup. As you do so, it will launch the VS Code application.
- Once you have opened the VS Code, you have to click on ‘File’. Following which, you have to select ‘New File’. And you can start typing Golang code.
- Since you are a beginner and have not learnt the syntax yet, it is better to copy paste a code from the official website, i.e, golang.org.
- If you scroll down, you will get to see the ‘Try Go’ section. You can copy the code (Hello World program) and paste it on VS Code.
- Next, we save the file as ‘main.go’ and on the desktop. Then, you will see that VS Code shows certain notifications asking you to install ‘Go’ extensions. These will help you with the development workflow. It will add debuggers, IntelliSense and much more.
Open Command Prompt Again
Again, you have to open the Command Prompt.
- You have to type ‘cd Desktop’
- Next, you type ‘dir’. When you do so, you will get to see a go file ‘main.go’
- Now, you have to compile the code. In order to do so, you have to type ‘go run main.go’
When you do so, you will get an output ‘Hello, World!’
You can also get the same output without opening Command Prompt. We can do it inside VS Code itself. For that, we have to take the help of Terminal.
Important Side Note:
The location where you have installed Go is the C drive. And if you visit Go, you will come across the bin folder. This is an extremely important folder, which contains two application files go and gofmt.
Just know this, you are able to run the code because of the go command. In case you face an error while running the code, it means that your path is not set correctly. In such instances, you have to set up the path manually for the bin by visiting Environment Variables.
Hopefully, you have an insight into Installing Golang in windows. You can see that the process is quite easy. If in any case, you get stuck with the process, just go through the process once more. However, if you feel that the task is daunting, then you can take the help of the Golang development services. The experts would be able to guide you through the entire process.