码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-01-10 15:30:50      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:版本   message   exe   相对   文档   语言   pen   hello   就是   

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

https://golang.org/doc/install;这里是go语言的官网文档。吃不透英文,终究会被限制在有限的区域,一词词的吃透。

安装包下载地址为:https://golang.org/dl/

如果打不开可以使用这个地址:https://golang.google.cn/dl/https://golang.google.cn/doc/install

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

说一下关于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

技术图片

 

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

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

标签:版本   message   exe   相对   文档   语言   pen   hello   就是   

原文地址:https://www.cnblogs.com/louis95/p/12176246.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!