Home > Backend Development > Golang > The difference between go build and go install in go language

The difference between go build and go install in go language

Release: 2019-11-28 14:57:58
forward
3123 people have browsed it

The difference between go build and go install in go language

go buildgo build is used to test the compiled package, mainly checking whether there are compilation errors. If it is an executable file The source code (that is, the main package) will directly generate an executable file.

go install: go install has two steps: the first step is to compile the imported package files. The main program will not be compiled until all imported package files are compiled; the second step is Place the compiled executable file in the bin directory ($GOPATH/bin), and the compiled package file in the pkg directory ($GOPATH/pkg).

go build

By go build plus the name of the Go source file to be compiled, we can get an executable file, by default The name of this file is the source file name minus the .go suffix.

$ go build hello.go
$ lshello hello.go
Copy after login

Of course we can also specify other names through the -o option:

$ go build -o mygo hello.go
$ lsmygo hello.go
Copy after login

If we directly execute the go build command in the go-examples directory without a file name, we will get An executable file with the same name as the directory name:

$ go build
$ lsgo-examples hello.go
Copy after login

go install

Compared with the build command, the install command also The executable file or library file will be installed in the agreed directory.

The executable file compiled by go install is named after the directory name (DIR) where it is located.

go install installs the executable file into the bin directory at the same level as src. The bin directory is created by go install automatically creates

go install compiles the various packages that the executable file depends on and places them in the pkg directory at the same level as src

Recommended: go language tutorial

The above is the detailed content of The difference between go build and go install in go language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template