【英文文档】 Installing Go from source Go语言官方编译指南 2019.02.27
Introduction
Go is an open source project, distributed under a BSD-style license. This document explains how to check out the sources, build them on your own machine, and run them.
Most users don't need to do this, and will instead install from precompiled binary packages as described in Getting Started, a much simpler process. If you want to help develop what goes into those precompiled packages, though, read on.
There are two official Go compiler toolchains. This document focuses on the gc Go compiler and tools. For information on how to work on gccgo, a more traditional compiler using the GCC back end, see Setting up and using gccgo.
The Go compilers support eight instruction sets. There are important differences in the quality of the compilers for the different architectures.
amd64(also known asx86-64)- A mature implementation.
386(x86orx86-32)- Comparable to the
amd64port. arm(ARM)- Supports Linux, FreeBSD, NetBSD, OpenBSD and Darwin binaries. Less widely used than the other ports.
arm64(AArch64)- Supports Linux and Darwin binaries. New in 1.5 and not as well exercised as other ports.
ppc64, ppc64le(64-bit PowerPC big- and little-endian)- Supports Linux binaries. New in 1.5 and not as well exercised as other ports.
mips, mipsle(32-bit MIPS big- and little-endian)- Supports Linux binaries. New in 1.8 and not as well exercised as other ports.
mips64, mips64le(64-bit MIPS big- and little-endian)- Supports Linux binaries. New in 1.6 and not as well exercised as other ports.
s390x(IBM System z)- Supports Linux binaries. New in 1.7 and not as well exercised as other ports.
Except for things like low-level operating system interface code, the run-time support is the same in all ports and includes a mark-and-sweep garbage collector, efficient array and string slicing, and support for efficient goroutines, such as stacks that grow and shrink on demand.
The compilers can target the DragonFly BSD, FreeBSD, Linux, NetBSD, OpenBSD, macOS (Darwin), Plan 9, Solaris and Windows operating systems. The full set of supported combinations is listed in the discussion of environment variables below.
See the main installation page for the overall system requirements. The following additional constraints apply to systems that can be built only from source:
- For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that Go does not support CentOS 6 on these systems.
Install Go compiler binaries
The Go toolchain is written in Go. To build it, you need a Go compiler installed. The scripts that do the initial build of the tools look for an existing Go tool chain in $GOROOT_BOOTSTRAP. If unset, the default value of GOROOT_BOOTSTRAP is $HOME/go1.4.
There are many options for the bootstrap toolchain. After obtaining one, set GOROOT_BOOTSTRAP to the directory containing the unpacked tree. For example, $GOROOT_BOOTSTRAP/bin/go should be the go command binary for the bootstrap toolchain.
To use a binary release as a bootstrap toolchain, see the downloads page or use any other packaged Go distribution.
To build a bootstrap toolchain from source, use either the git branch release-branch.go1.4 or go1.4-bootstrap-20171003.tar.gz, which contains the Go 1.4 source code plus accumulated fixes to keep the tools running on newer operating systems. (Go 1.4 was the last distribution in which the toolchain was written in C.) After unpacking the Go 1.4 source, cd to the src subdirectory, set CGO_ENABLED=0 in the environment, and run make.bash (or, on Windows, make.bat).
To cross-compile a bootstrap toolchain from source, which is necessary on systems Go 1.4 did not target (for example, linux/ppc64le), install Go on a different system and run bootstrap.bash.
When run as (for example)
$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash
bootstrap.bash cross-compiles a toolchain for that GOOS/GOARCH combination, leaving the resulting tree in ../../go-${GOOS}-${GOARCH}-bootstrap. That tree can be copied to a machine of the given target type and used as GOROOT_BOOTSTRAP to bootstrap a local build.
To use gccgo as the bootstrap toolchain, you need to arrange for $GOROOT_BOOTSTRAP/bin/go to be the go tool that comes as part of gccgo 5. For example on Ubuntu Vivid:
$ sudo apt-get install gccgo-5
$ sudo update-alternatives --set go /usr/bin/go-5
$ GOROOT_BOOTSTRAP=/usr ./make.bash
Install Git, if needed
To perform the next step you must have Git installed. (Check that you have a git command before proceeding.)
If you do not have a working Git installation, follow the instructions on the Git downloads page.
(Optional) Install a C compiler
To build a Go installation with cgo support, which permits Go programs to import C libraries, a C compiler such as gcc or clang must be installed first. Do this using whatever installation method is standard on the system.
To build without cgo, set the environment variable CGO_ENABLED=0 before running all.bash or make.bash.
Fetch the repository
Go will install to a directory named go. Change to the directory that will be its parent and make sure the go directory does not exist. Then clone the repository and check out the latest release tag (go1.12, for example):
$ git clone https://go.googlesource.com/go
$ cd go
$ git checkout go1.12
(Optional) Switch to the master branch
If you intend to modify the go source code, and contribute your changes to the project, then move your repository off the release branch, and onto the master (development) branch. Otherwise, skip this step.
$ git checkout master
Install Go
To build the Go distribution, run
$ cd src
$ ./all.bash
(To build under Windows use all.bat.)
If all goes well, it will finish by printing output like:
ALL TESTS PASSED ---
Installed Go for linux/amd64 in /home/you/go.
Installed commands in /home/you/go/bin.
*** You need to add /home/you/go/bin to your $PATH. ***
where the details on the last few lines reflect the operating system, architecture, and root directory used during the install.
For more information about ways to control the build, see the discussion of environment variables below. all.bash (or all.bat) runs important tests for Go, which can take more time than simply building Go. If you do not want to run the test suite use make.bash (or make.bat) instead.
Testing your installation
Check that Go is installed correctly by building a simple program.
Create a file named hello.go and put the following program in it:
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
Then run it with the go tool:
$ go run hello.go
hello, world
If you see the "hello, world" message then Go is installed correctly.
Set up your work environment
You're almost done. You just need to do a little more setup.
How to Write Go Code Learn how to set up and use the Go tools
The How to Write Go Code document provides essential setup instructions for using the Go tools.
Install additional tools
The source code for several Go tools (including godoc) is kept in the go.tools repository. To install one of the tools (godoc in this case):
$ go get golang.org/x/tools/cmd/godoc
To install these tools, the go get command requires that Git be installed locally.
You must also have a workspace (GOPATH) set up; see How to Write Go Code for the details.
Community resources
The usual community resources such as #go-nuts on the Freenode IRC server and the Go Nuts mailing list have active developers that can help you with problems with your installation or your development work. For those who wish to keep up to date, there is another mailing list, golang-checkins, that receives a message summarizing each checkin to the Go repository.
Bugs can be reported using the Go issue tracker.
Keeping up with releases
New releases are announced on the golang-announce mailing list. Each announcement mentions the latest release tag, for instance, go1.12.
To update an existing tree to the latest release, you can run:
$ cd go/src
$ git fetch
$ git checkout go1.12
Optional environment variables
The Go compilation environment can be customized by environment variables. None is required by the build, but you may wish to set some to override the defaults.
$GOROOTThe root of the Go tree, often
$HOME/go1.X. Its value is built into the tree when it is compiled, and defaults to the parent of the directory whereall.bashwas run. There is no need to set this unless you want to switch between multiple local copies of the repository.$GOROOT_FINALThe value assumed by installed binaries and scripts when
$GOROOTis not set explicitly. It defaults to the value of$GOROOT. If you want to build the Go tree in one location but move it elsewhere after the build, set$GOROOT_FINALto the eventual location.$GOOSand$GOARCHThe name of the target operating system and compilation architecture. These default to the values of
$GOHOSTOSand$GOHOSTARCHrespectively (described below).
Choices for $GOOS are darwin (macOS 10.10 and above and iOS), dragonfly, freebsd, linux, netbsd, openbsd, plan9, solaris and windows. Choices for $GOARCH are amd64 (64-bit x86, the most mature port), 386 (32-bit x86), arm (32-bit ARM), arm64 (64-bit ARM), ppc64le (PowerPC 64-bit, little-endian), ppc64 (PowerPC 64-bit, big-endian), mips64le (MIPS 64-bit, little-endian), mips64 (MIPS 64-bit, big-endian), mipsle (MIPS 32-bit, little-endian), mips (MIPS 32-bit, big-endian), and s390x (IBM System z 64-bit, big-endian). The valid combinations of $GOOS and $GOARCH are:
$GOOS |
$GOARCH |
|
|---|---|---|
android |
arm |
|
darwin |
386 |
|
darwin |
amd64 |
|
darwin |
arm |
|
darwin |
arm64 |
|
dragonfly |
amd64 |
|
freebsd |
386 |
|
freebsd |
amd64 |
|
freebsd |
arm |
|
linux |
386 |
|
linux |
amd64 |
|
linux |
arm |
|
linux |
arm64 |
|
linux |
ppc64 |
|
linux |
ppc64le |
|
linux |
mips |
|
linux |
mipsle |
|
linux |
mips64 |
|
linux |
mips64le |
|
linux |
s390x |
|
netbsd |
386 |
|
netbsd |
amd64 |
|
netbsd |
arm |
|
openbsd |
386 |
|
openbsd |
amd64 |
|
openbsd |
arm |
|
plan9 |
386 |
|
plan9 |
amd64 |
|
solaris |
amd64 |
|
windows |
386 |
|
windows |
amd64 |
$GOHOSTOSand$GOHOSTARCHThe name of the host operating system and compilation architecture. These default to the local system's operating system and architecture.
Valid choices are the same as for $GOOS and $GOARCH, listed above. The specified values must be compatible with the local system. For example, you should not set $GOHOSTARCH to arm on an x86 system.
$GOBINThe location where Go binaries will be installed. The default is
$GOROOT/bin. After installing, you will want to arrange to add this directory to your$PATH, so you can use the tools. If$GOBINis set, the go command installs all commands there.$GO386(for386only, default is auto-detected if built on either386oramd64,387otherwise)This controls the code generated by gc to use either the 387 floating-point unit (set to
387) or SSE2 instructions (set tosse2) for floating point computations.GO386=387: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).GO386=sse2: use SSE2 for floating point operations; has better performance than 387, but only available on Pentium 4/Opteron/Athlon 64 or later.
$GOARM(forarmonly; default is auto-detected if building on the target processor, 6 if not)This sets the ARM floating point co-processor architecture version the run-time should target. If you are compiling on the target system, its value will be auto-detected.
GOARM=5: use software floating point; when CPU doesn't have VFP co-processorGOARM=6: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)GOARM=7: use VFPv3; usually Cortex-A cores
If in doubt, leave this variable unset, and adjust it if required when you first run the Go executable. The GoARM page on the Go community wiki contains further details regarding Go's ARM support.
$GOMIPS(formipsandmipsleonly)
$GOMIPS64(formips64andmips64leonly)These variables set whether to use floating point instructions. Set to "
hardfloat" to use floating point instructions; this is the default. Set to "softfloat" to use soft floating point.
Note that $GOARCH and $GOOS identify the
target environment, not the environment you are running on.
In effect, you are always cross-compiling.
By architecture, we mean the kind of binaries
that the target environment can run:
an x86-64 system running a 32-bit-only operating system
must set GOARCH to 386,
not amd64.
If you choose to override the defaults,
set these variables in your shell profile ($HOME/.bashrc,
$HOME/.profile, or equivalent). The settings might look
something like this:
export GOARCH=amd64
export GOOS=linux
although, to reiterate, none of these variables needs to be set to build, install, and develop the Go tree.
【英文文档】 Installing Go from source Go语言官方编译指南 2019.02.27的更多相关文章
- PHP-redis英文文档
作为程序员,看英文文档是必备技能,所以尽量还是多看英文版的^^ PhpRedis The phpredis extension provides an API for communicating wi ...
- openstack【Kilo】汇总:包括20英文文档、各个组件新增功能及Kilo版部署
OpenStack Kilo版本发布 20英文文档OpenStack Kilo版本文档汇总:各个操作系统安装部署.配置文档.用户指南等文档 Kilo版部署 openstack[Kilo]入门 [准备篇 ...
- py爬取英文文档学习单词
最近开始看一些整本整本的英文典籍,虽然能看个大概,但是作为四级都没过的我来说还是有些吃力,总还有一部分很关键的单词影响我对句子的理解,因为看的是纸质的,所以查询也很不方便,于是想来个突击,我想把程序单 ...
- 英文文档帮查&翻译计划
以CSDN为首,知乎其次,cnblog带路的一大批博客上充斥着大量低质量的编程入门教程,代码粗制滥造,毫无缩进,没有高亮,东抄西抄.初学者如果长期参照这种垃圾博客来解决问题,将会适得其反,走入歧途. ...
- Python3求英文文档中每个单词出现的次数并排序
[本文出自天外归云的博客园] 题目要求: 1.统计英文文档中每个单词出现的次数. 2.统计结果先按次数降序排序,再按单词首字母降序排序. 3.需要考虑大文件的读取. 我的解法如下: import ch ...
- gitlab安装教程、gitlab官网、英文文档
gitlab官网 https://about.gitlab.com/ gitlab安装和官网英文文档 https://about.gitlab.com/downloads/ 清华大学tuna镜像源 G ...
- Android 英文文档下载地址
通过英文Android API学习Android技术是一个不错选择,当然养鸡的专业户要小心了,以下分享一些下载英文文档的链接(请使用迅雷下载): https://dl-ssl.google.com/a ...
- python3 怎么统计英文文档常用词?(附解释)
# coding: utf-8 # In[32]: #import requests #from bs4 import BeautifulSoup #res = requests.get(" ...
- 利用谷歌翻译网站和Adobe Acrobat翻译英文文档,且鼠标放置后显示英文原文(无字数限制)(18/12/11更新)
软件:Adobe Acrobat 网页:https://translate.google.cn/?tr=f&hl=zh-CN 方法: 第一步:用Adobe Acrobat 打开英文 ...
随机推荐
- Codeforces963C Cutting Rectangle 【数学】
错了一个小地方调了一晚上.... 题目大意: 给出最多2E+5种不同的矩形,每种有它的长h和宽v还有数量d,现在你要构造大矩形,使得在上面沿着平行于长或宽的边划刀,切出来的矩形正好是给出的所有矩形.问 ...
- hdu 4825 Xor Sum (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...
- Educational Codeforces Round 54 [Rated for Div. 2] (CF1076)
第一次在宿舍打CF 把同宿舍的妹子吵得不行... 特此抱歉QAQ A 题意:给定一个字符串, 最多删掉一个字符,使得剩余字符串字典序最小 n<=2e5 当然"最多"是假的 删 ...
- LG P2473 [SCOI2008]奖励关
题目链接:P2473 [SCOI2008]奖励关 题意:有n个宝物 每次等概率抛出其中之一一共抛出k次每个宝物有一个价值 和一个前提集合只有集齐了集合中的所有宝物 才可以领取这个宝物 范围:1 < ...
- 用keras实现基本的图像分类任务
数据集介绍 fashion mnist数据集是mnist的进阶版本,有10种对应的结果 训练集有60000个,每一个都是28*28的图像,每一个对应一个标签(0-9)表示 测试集有10000个 代码 ...
- Android RadioGroup 学习
Api 参考地址 博文地址 RadioGroup相关属性: //返回该单选按钮组中所选择的单选按钮的标识 ID,如果没有选中的单选按钮则返回 -1. RadioGroup.getCheckedRadi ...
- 深度分析Java的枚举类型—-枚举的线程安全性及序列化问题
原文:深度分析Java的枚举类型--枚举的线程安全性及序列化问题 枚举是如何保证线程安全的 要想看源码,首先得有一个类吧,那么枚举类型到底是什么类呢?是enum吗?答案很明显不是,enum就和clas ...
- luogu3188/bzoj1190 梦幻岛宝珠 (分层背包dp)
他都告诉你能拆了 那就拆呗.把每个重量拆成$a*2^b$的形式 然后对于每个不同的b,先分开做30个背包 再设f[i][j]表示b<=i的物品中 容量为$ j*2^i+W\&((1< ...
- 【php】php位运算及其高级应用
我们之前学过逻辑与(&&) 条件1 && 条件2 当两边条件同时成立时候返回1 逻辑或(||) 条件1 || 条件2 当两边条件只要有一 ...
- 分页技术 -servlet
一.思路: 定义四个分页变量. pagenow 表示第几页,该变量由用户决定的,是变化的. pageSize 每页显示几条记录,由程序定义,也可以由程序定制. pageCount 表示共有多少页,(该 ...