Go Installation and Configuration Run

A must-see guide to configuring and running Go environment variables for newbies.

Go download link:studygolang.com/dl

We can go directly to the Go language Chinese website to find the latest version of the current stable operation (currently 2020-11-08 is 1.15.4), and then find a Windows system to download (as shown in the figure):

There are two options for downloading the zip archive or the msi installer. To save time, we’ll download a zip archive, the first one in the red box, go.15.4.windows-386.zip.

Once the download is complete, unzip it to a directory on your computer, this is the directory I unzipped locally, and then go to the bin directory after unzipping the package:

Then right click on this computer (for Win7 etc. open My Computer) and go to the properties page:

Open Advanced System Settings, Environment Variables, and edit the value of Path in System Variables:

Then add the address of the bin directory:

And finally, to check if we’ve configured it successfully, first, call out the command line (shortcut Win + R) and type cmd:

在任意目录下输入 go version:

The Go version 1.15.4 we just downloaded appears, la la la la ~~ Congratulations, the configuration is successful!

运行 Go 程序

Now we can run our Go program directly from the command line.

First, from the command line, go to the Go file directory. For example, my current helloworld.go is in the C:\Users\37595\Desktop\KnowledgeBase\code\1_helloworld directory:

  1. There are two ways to run it:
    1. go build compiles helloworld, and after successful compilation, a new .exe file is added to the directory:

Execute the compiled file:

  1. The go run command is executed directly:

  • Summary

    • You may have noticed that we didn’t use the traditional installer method to configure the Go environment, but instead downloaded the .zip file and unzipped it to configure the environment variables. The difference between this and the .msi installation is that it doesn’t write any configuration information into our computer’s registry, and it can’t generate shortcuts. Therefore, if you are already familiar with the installation process, or want to save time, you can choose the .zip installation method directly, and you can also run the Go program normally!
    • After compiling the Go program, it will be an executable .exe file, which can still be run on computers that do not have the Go compilation package installed and configured, just like Java and other programming languages, which can be compiled once and run everywhere. The difference is that the .class bytecode file generated after Java compilation needs to be run on the JVM (Java Virtual Machine), while the .exe file compiled by Go can be opened and run directly on a Windows machine.

PS:Some operating system computers will flash back after opening the .exe file directly, in this case, you can add a line at the end of the code to get the input parameter code from the keyboard on it:

1
fmt.Scanf("a")