因好奇而走進go語言,讓你不在只聞其聲,不見其形。html
https://golang.org/doc/install;這裏是go語言的官網文檔。吃不透英文,終究會被限制在有限的區域,一詞詞的吃透。golang
安裝包下載地址爲:https://golang.org/dl/。ide
若是打不開能夠使用這個地址:https://golang.google.cn/dl/。https://golang.google.cn/doc/install。測試
想了想,具體步驟就不提了,英文內容夠全了。ui
說一下關於SettingGOPATH的中外差異:this
就像原文所說,「 If no GOPATH
is set, it is assumed to be $HOME/go
on Unix systems and %USERPROFILE%\go
on Windows.」google
那麼這個GOPATH竟然是在環境變量的用戶變量中;spa
那麼,原文中:code
Your workspace can be located wherever you like, but we'll use C:\go-work
in this example.htm
NOTE: GOPATH
must not be the same path as your Go installation.
C:\go-work
.GOPATH
into the "Variable name" field.C:\go-work
into the "Variable value" field.這段就是說將GOPATH這個環境變量的值由原來的%USERPROFILE%\go替換爲你的go工做空間的目錄。保存環境變量更改後,記得重啓電腦是其生效(win10)。
原文中是這樣使test.go生效的並測試的:
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.
可是,按舊有方式,還可在終端執行:go run hello.go
使用原文中的生成hello.exe文件得使用當前目錄相對路徑執行hello.exe這種方式。
更新:
1. 由於go version >= 1.13,因此go env -w GO111MODULE=on修改相應依賴模式,go env查看