Home  >  Article  >  Backend Development  >  The difference between go build and go install

The difference between go build and go install

尚
forward
2020-01-03 16:15:092881browse

Go (also known as Golang) is a statically strongly typed, compiled language developed by Google's Robert Griesemer, Rob Pike and Ken Thompson. This tutorial will introduce to you the difference between go build and go install in go language.

The difference between go build and go install

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

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

$ go build -o mygo hello.go
$ lsmygo hello.go

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

go install

Compared with the build command, the install command will also install the executable file or The library files are 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

For more golang knowledge, please pay attention to the PHP Chinese websitegolang tutorial column.

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

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete