download
Download – The Go Programming Language (golang.org)
Windows installation
Download the file to install
The latest stable version is GO1.15, Windows download address: GO1.15.5
-
Open the downloaded file, and then next, next, the default installation in C:\Go directory, if necessary can be installed when the change, you can also reopen the command program installation.
-
To confirm that Go is installed, run the CMD command to open the command window and enter the following command:
$ go version Copy the code
Ii. Use scoop installation
Scoop is a community-provided Windows package management tool solution that installs Windows applications using the command line
Open the command line and enter the following command to search for go:
$ scoop search go
Copy the code
Enter the following command to install:
$ scoop install go
Copy the code
After the installation is complete, enter Go Version to view the current installed version, or use scoop Install [email protected] to install the specified version, and scoop uninstall Go to delete the installation package
Linux installation
-
Download the file and decompress it to the /usr/local directory. Create a go directory tree in the /usr/local directory
For example, run the following command as root or as sudo:
Tar -c /usr/local-xzf go1.15.5.linux-amd64.tar.gzCopy the code
-
Add the /usr/local/go/bin directory to the PATH environment variable
You can add the following command to $HOME/. Profile or /etc/profile (for all system users) to complete the addition of environment variables:
Add the /usr/local/go/bin directory to the PATH environment variableCopy the code
-
After the installation is complete, enter Go version to view the current version
Set up the Go Modules and proxy
Go Modules is the Go language dependency management solution
Mod file field content
Go.mod is the most important file required for a Go Moduels-enabled project. It describes the meta information for the current project (that is, the current module), and each line begins with a verb, which currently has the following five verbs:
- Module: Defines the module path for the current project.
- Go: Used to set the expected GO version.
- Require: Used to set a specific module version.
- Exclude: Used to exclude a particular module version from use.
- Replace: Used to replace one module version with another.
Open the go. The mod
- Open Go Modules:
go env -w GO111MODULE=on
. - Set GOPROXY:
go env -w GOPROXY=https://goproxy.cn,direct
# is required in China because its default value is blocked. - Execute in the root directory of your project
go mod init <OPTIONAL_MODULE_PATH>
To generate the go.mod file.
Go modules Common command
-
Use Go Help module-get and Go Help Gopath -get to understand the go Get behavior in the go Modules enabled and not enabled states respectively
-
Pull new dependencies with Go Get
- Pull the latest version (tag is preferred) :
go get golang.org/x/text@latest
- pull
master
Branch’s latest COMMIT:go get golang.org/x/text@master
- Pull commit with tag v0.3.2:
Go get golang.org/x/[email protected]
- Pull commit with hash 342b231, which will be converted to v0.3.2:
go get golang.org/x/text@342b2e
- with
go get -u
Update existing dependencies - with
go mod download
Download all dependencies specified in the go.mod file - with
go mod tidy
Sort out existing dependencies - with
go mod graph
Look at existing dependency structures - with
go mod init
Generate go.mod files (the only subcommand in Go 1.13 that can generate go.mod files)
- Pull the latest version (tag is preferred) :
-
Edit the go.mod file with Go Mod Edit
-
Export all existing dependencies with Go Mod Vendor (actually Go Modules are de-emphasizing the concept of vendor)
-
Use Go Mod Verify to verify if a module has been tampered with