Install Go on Windows 10

Table of Contents

alt=Go On Windows Image

  1. Download MSI installer
  2. After the download is complete, open the downloaded msi file and follow the prompts to install Go. By default, the installer places the files in the c:\Go folder and also adds the c:\go\bin directory to your PATH environment variable.
  3. Create a working directory for your Go projects and change to this newly created folder. This will be your Go workspace and should be separate from your Go installation folder. I will use c:\go-projects for this example.
      mkdir c:\go-projects & cd c:\go-projects
  1. Create a GOPATH environment variable with the value of the folder c:\go-projects your created above

  2. Add %GOPATH%\bin to the PATH environment variable

  3. Within the directory you have created, create bin, pkg and src folders.

     mkdir bin pkg src
    

After you have completed the process, your folder structure should resemble the following:
- c:\go-projects\bin - c:\go-projects\pkg - c:\go-projects\src

  1. Every time you create a new project, you should create a new folder in the src directory for the project.

Testing the installation

  1. Change directory to your %GOPATH%\src folder.

    cd c:\go-projects\src
    
  2. Create a folder hello inside your %GOPATH%\src. This will be the folder for the testing project

    mkdir hello & cd hello
    
  3. Inside the hello folder, create a file (using Notepad or your preferred text editor) named hello.go that looks like:

    package main
    
    import "fmt"
    
    func main(){
       fmt.Println("\nSuccessfully installed and configured Go\n")
    }
  4. Open the command prompt and run the following command:

      go run hello.go

If you see ‘Successfully installed and configured Go’ message then your Go installation is configured and working.

Following is the full set of commands used in the example above.

c:\>mkdir c:\go-projects & cd c:\go-projects

c:\go-projects>mkdir bin pkg src

c:\go-projects>cd c:\go-projects\src

c:\go-projects\src>mkdir hello & cd hello

c:\go-projects\src\hello>

c:\go-projects\src\hello>go run hello.go

Successfully installed and configured Go

C:\go-projects\src\hello>