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:

  1. 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.

  2. 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:

https://golang.org/LICENSE

Go-language

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.

  1. Open the Command Prompt by typing “cmd” in the search bar of your system. 
    Go-language
  2. 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:
      Go-language
    • 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:
      Go-language

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:

  1. Go to website https://golang.org/
  2. Click on the link: “Download Go”.
    Go-language
  3. 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)

    Go-language
  4. Run the downloaded Go installer from the download folder.
  5. Then a dialogue box as shown below will appear and click the “Next” button to continue the installation process.
    Go-language
  6. In the next window, accept the end-user license agreement, then click the “Next” button. 
    Go-language
  7. 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.
      Go-language
  8. Click the “Install” button to start the installation. 
    Go-language
  9. 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.
    Go-language
  10. 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.
    Go-language
  11. To ensure the proper installation of Go, open the Command Prompt again and type the following command: 
    go version
  12. If the command prints the currently installed version of Go as shown in the screenshot below, then the installation of Go is successful.
    Go-language

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.

  1.     First, let’s create a Go file for that open Notepad by typing “Notepad” in the search bar of your system
    Go-language
  2.    Type or copy and paste the Go commands below into the Notepad.
    
    package main  
    import ("fmt")  
    func main(){  
       fmt.Println("Hello, World!")  
    }
    
    
    Go-language
  3.     Save the file by pressing Ctrl + S or selecting the Save option from the File menu.
    Go-language
  4.     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:
    Go-language
  5.     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:
    Go-language
  6.     Now type the following command in the Command Prompt and press Enter to run the program.

    go run HelloWorld.go

    Go-language
  7.     To save the same program as an executable file, type the following command and press Enter: Go build HelloWorld.go
    Go-language
  8.     To see the executable file just created, open the folder where the Helloworld (your Go file) file is saved. 
    Go-language

    This executable file can be accessed in the Command Prompt as shown in the screenshot below:

    Go-language