在Ubuntu上安装Go 1.7的最佳方法
Go是谷歌在2007年创建的一种自由和开源的编程语言。它为构建简单、无毒和有效的程序提供了便利。这种语言是为在服务器上写作而设计的。这篇文章介绍了 “如何在Ubuntu上安装Go 1.7″。
安装Go编程语言
要下载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环境,请使用以下步骤-
要设置GOROOT环境变量,请使用下面的命令 —
$ export GOROOT=/usr/local/go
要为工作地点设置GOPATH,使用以下命令 –
$ export GOPATH=$HOME/tutorialspoint/sample
要设置PATH变量以访问二进制系统,使用以下命令 –
$ export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
永久设置
永久设置应该适用于所有的时间。要设置围棋环境,请使用以下步骤– 1.
要打开.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/tutorialspoint/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/tutorialspoint/tutorialspoint/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的技巧和提示。继续阅读!