Setting up environment for personal installation of go1.13.6

Time:2020-11-28

Because of curiosity and into the go language, let you not only hear its sound, not see its shape.

https://golang.org/doc/install This is the official website document of go language. If you can’t eat English well, you will be limited to a limited area.

Download the installation package at: https://golang.org/dl/ 。

If you can’t open it, you can use this address: https://golang.google.cn/dl/ 。 https://golang.google.cn/doc/install 。

After thinking about it, I will not mention the specific steps. The English content is complete enough.

Let’s talk about the differences between Chinese and foreign countries about setting gopath

As the original says, “if no”GOPATH is set, it is assumed to be $HOME/go on Unix systems and %USERPROFILE%\go on Windows.”

The gopath is actually in the user variable of the environment variable;

In the original text:

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 Go installation.

  • Create 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”.
  • Click the “Environment Variables” button at the bottom.
  • Click “New” from the “User variables” section.
  • Type GOPATH into the “Variable name” field.
  • Type C:\go-work into the “Variable value” field.
  • Click OK.

This is to replace the value of gopath environment variable from the original% userprofile% \ go to the directory of your go workspace. After saving the environment variable changes, remember to restart the computer to make it take effect (win10).

In the original text, it is like this test.go Effective and tested:

Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.

Create your workspace directory, %USERPROFILE%\go. (If you’d like to use a different directory, you will need to set the GOPATH environment variable.)

Next, make the directory src\hello inside your workspace, and in that directory create a file named hello.go that looks like:

package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}

Then build it with the go tool:

C:\> cd %USERPROFILE%\go\src\hello
C:\Users\Gopher\go\src\hello> go build

The command above will build an executable named hello.exe in the directory alongside your source code. Execute it to see the greeting:

C:\Users\Gopher\go\src\hello> hello
hello, world

If you see the “hello, world” message then your Go installation is working.

You can run go install to install the binary into your workspace’s bin directory or go clean -i to remove it.

Before rushing off to write Go code please read the How to Write Go Code document, which describes some essential concepts about using the Go tools.

However, in the old way, it can also be executed at the terminal: go run hello.go

 

Use the generation in the original text hello.exe Relative to the current directory hello.exe This way.

 

to update:

1. Because go version > = 1.13, go env – w go111module = on modify the corresponding dependency mode, go env view