Installation of Go in Windows
From this tutorial, you will learn topics that are related to the environment setup of Go programming.
Need to spend money to buy GO?
Since Go has an open-source software license, there is no need to spend money to buy Go. Its source code is freely available to anyone. Go can be used for personal or commercial purposes without paying anyone. The libraries, compiler, and tools of Go are free to everyone everywhere.
What is a software license?
A software license is a contract that is a text document between the developer or organization that created and distributed an application, source code, or related product and its end-user. A software license has the right to protect the intellectual property of the developer or organization and to restrict any claims against them. It also provides legal statements for the installation, warranties, liabilities, distribution, and use of the software.
The software licenses are categorized mainly into two, they are:
- Proprietary (or Closed-source):
The software which has a proprietary license is restricted for its code duplication, modification, reuse, or distribution. This type of software’s operational code is only provided not the source code.
- Free and Open-Source Software (FOSS):
It is also referred to as “open-source”. This license gives permission to the end-user for software modification, reuse of the software code, and also provides the actual source code with the software products.
What type of license does Go have?
Go has a BSD (Berkeley Software Distribution) style license. This license is also referred to as “Permissive” or “Apache”. BSD is a popular open-source software license. BSD is a simple license that only requires that all code keep the BSD license notice if re-distributed in source code format or reproduce the notice if re-distributed in binary format. The BSD license does not require that source code be distributed at all.
Visit this link to see the original license of Go:
On which operating system can Go be installed?
Go is a portable software which means that it does not depend on a single operating system. Hence, "Go" can be installed on several operating systems like Windows, Linux, macOS/iOS, Solaris, etc.
Check if Go is installed on your system or not
You are advised to check if this software is already installed on your system because it will save you valuable time and effort from the installation process.
Follow the instructions and corresponding pictures given below to check if Go is already installed on your system or not.
- Open the Command Prompt by typing “cmd” in the search bar of your system.
- Type “go version” in the Command Prompt and press Enter.
- If Go is not installed on your system, then a message will be displayed as shown in the screenshot below:
- If "Go" is already installed on your system, then the version of Go that is currently available on your system will be displayed as shown in the screenshot below:
If Go is already installed on your system, you can skip the installation process and if Go is not installed on your system, then let’s start the installation of Go:
Installation of Go:
Follow the steps and corresponding pictures given below to install Go in your system:
- Go to website https://golang.org/
- Click on the link: “Download Go”.
- Download the corresponding Go installer for your operating system.
(Other versions of Golang for different operating systems are available on the same page. You can also download the older version of Golang but, advised to use the latest one)
- Run the downloaded Go installer from the download folder.
- Then a dialogue box as shown below will appear and click the “Next” button to continue the installation process.
- In the next window, accept the end-user license agreement, then click the “Next” button.
- The next step is to select the folder where you would like to install Go in your system.
- To proceed with the installation in the default destination folder, click the “Next” button.
- But if you want to install Go in another folder, then click on the “change…” button and then set the location.
- Click the “Install” button to start the installation.
- Now the installation process will begin, and the window will show the current status of the installation of Go. Wait for the installation to complete.
- Once the installation is complete, a window as shown below will appear to inform you that the Go installation is completed successfully in your system. Click the “Finish” button to complete the installation.
- To ensure the proper installation of Go, open the Command Prompt again and type the following command:
- If the command prints the currently installed version of Go as shown in the screenshot below, then the installation of Go is successful.
Basic Program to Print “Hello World” Using Text Editor and Command Prompt:
Follow the steps and corresponding pictures given below to create and execute a simple Go program:
We will use Notepad as the text editor. You can use other text editors as well.
- First, let’s create a Go file for that open Notepad by typing “Notepad” in the search bar of your system
- Type or copy and paste the Go commands below into the Notepad.
- Save the file by pressing Ctrl + S or selecting the Save option from the File menu.
- The Save As window will appear. In the window, set the location to save the Go file, and type Filename as HelloWorld and type extension as “.GO”. Then set Save as type as “All Files” as shown in the screenshot below. Then click on the “Save” button:
- Now open the Command Prompt by typing “cmd” in the search bar. Open the folder where the Go file is saved using the “cd” (change directory) command. If your Go file is saved in a subfolder then open each subfolder using the “cd” command as shown in the screenshot below:
- Now type the following command in the Command Prompt and press Enter to run the program.
go run HelloWorld.go
- To save the same program as an executable file, type the following command and press Enter: Go build HelloWorld.go
- To see the executable file just created, open the folder where the Helloworld (your Go file) file is saved.
This executable file can be accessed in the Command Prompt as shown in the screenshot below: