欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

个人安装GO1.13.6版本指南手册之搭建环境

程序员文章站 2022-05-23 12:32:23
因好奇而走进go语言,让你不在只闻其声,不见其形。 https://golang.org/doc/install;这里是go语言的官网文档。吃不透英文,终究会被限制在有限的区域,一词词的吃透。 安装包下载地址为:https://golang.org/dl/。 如果打不开可以使用这个地址:https: ......

因好奇而走进go语言,让你不在只闻其声,不见其形。

;这里是go语言的官网文档。吃不透英文,终究会被限制在有限的区域,一词词的吃透。

安装包下载地址为:。

如果打不开可以使用这个地址:。。

想了想,具体步骤就不提了,英文内容够全了。

说一下关于settinggopath的中外差别:

就像原文所说,“ if no gopath is set, it is assumed to be $home/go on unix systems and %userprofile%\go on windows.”

那么这个gopath居然是在环境变量的用户变量中;

那么,原文中:

your workspace can be located wherever you like, but we'll use c:\go-work in this example.

note: gopath must not be the same path as your go installation.

  • create folder at c:\go-work.
  • right click on "start" and click on "control panel". select "system and security", then click on "system".
  • from the menu on the left, select the "advanced systems settings".
  • click the "environment variables" button at the bottom.
  • click "new" from the "user variables" section.
  • type gopath into the "variable name" field.
  • type c:\go-work into the "variable value" field.
  • click ok.

这段就是说将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

个人安装GO1.13.6版本指南手册之搭建环境

 

 使用原文中的生成hello.exe文件得使用当前目录相对路径执行hello.exe这种方式。

 

更新:

1. 因为go version >= 1.13,所以go env -w go111module=on修改相应依赖模式,go env查看