Go是Google在2007年创建的一种免费开放源代码编程语言。它提供了构建简单,无毒且有效的程序的便利。此语言是为在服务器上编写而设计的。本文介绍了“如何在Ubuntu上安装Go 1.7”
要下载Go语言二进制存档文件,请使用以下命令-
$ wget https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz
样本输出应如下所示–
--2016-12-29 10:49:44-- https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz Resolving storage.googleapis.com (storage.googleapis.com)... 216.58.197.48, 2404:6800:4007:807::2010 Connecting to storage.googleapis.com (storage.googleapis.com)|216.58.197.48|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 81618401 (78M) [application/x-gzip] Saving to: ‘go1.7.1.linux-amd64.tar.gz’ go1.7.1.linux-amd64 100%[===================>] 77.84M 5.98MB/s in 16s 2016-12-29 10:50:01 (4.78 MB/s) - ‘go1.7.1.linux-amd64.tar.gz’ saved [81618401/81618401]
要提取下载的存档文件并移至系统上的所需位置,请使用以下命令–
$ sudo tar -zxvf go1.7.1.linux-amd64.tar.gz -C /usr/local/
样本输出应如下所示–
go/ go/AUTHORS go/CONTRIBUTING.md go/CONTRIBUTORS go/LICENSE go/PATENTS go/README.md go/VERSION go/api/ go/api/README go/api/except.txt go/api/go1.1.txt go/api/go1.2.txt go/api/go1.3.txt go/api/go1.4.txt go/api/go1.5.txt go/api/go1.6.txt go/api/go1.7.txt go/api/go1.txt go/api/next.txt go/bin/ go/bin/go go/bin/godoc go/bin/gofmt go/blog/ go/blog/content/ go/blog/content/4years-gopher.png go/blog/content/4years-graph.png go/blog/content/4years.article go/blog/content/5years/ go/blog/content/5years/conferences.jpg go/blog/content/5years/gophers5th.jpg go/blog/content/5years.article go/blog/content/6years-gopher.png go/blog/content/6years.article go/blog/content/a-conversation-with-the-go-team.article go/blog/content/advanced-go-concurrency-patterns.article go/blog/content/appengine-dec2013.article .......................................................................
有两种设置Go Environment的方法。以下是如下所示的方法–
本届会议
永久设置
当前会话设置应仅适用于当前工作会话。要设置Go环境,请使用以下步骤-
要设置GOROOT环境变量,请使用以下命令-
$ export GOROOT=/usr/local/go
要为工作地点设置GOPATH,请使用以下命令-
$ export GOPATH=$HOME/nhooo/sample
要将PATH变量设置为访问go二进制系统,请使用以下命令-
$ export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
永久设置应始终适用。要设置Go环境,请使用以下步骤-
要打开.profile文件,请使用以下命令-
$ sudo nano ~/.profile
样本输出应如下所示–
# ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. # see /usr/share/doc/bash/examples/startup-files for examples. # the files are located in the bash-doc package. # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022 ...............................................................
现在,在文件末尾添加以下行,如下所示–
export GOROOT=/usr/local/go export GOPATH=$HOME/nhooo/sample export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
现在保存并关闭文件。要刷新您的个人资料,请使用以下命令-
$ source ~/.profile
要验证go版本,请使用以下命令-
$ go version
样本输出应如下所示–
go version go1.7.1 linux/amd64
要验证所有已配置的环境变量,请使用以下命令–
$ go env
样本输出应如下所示–
GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/nhooo/nhooo/sample" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build771783301=/tmp/go-build -gno-record-gcc-switches" CXX="g++" CGO_ENABLED="1"
在阅读完本文之后,您将能够理解–如何在Ubuntu 16.04上安装Go 1.7。在我们的下一篇文章中,我们将提出更多基于Linux的技巧。继续阅读!