This is a creation in Article, where the information may have evolved or changed.
Download Address: https://golang.org/dl/
Download the compressed package
$ wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
Unzip the file, the default go path under/usr/local, create a go structure in/usr/local/go.
Format: Tar-c/usr/local-xzf go$version. $OS-$ARCH. tar.gz
$ sudo tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz
SOURCE Installation
提示:我这里采用root账号进行安装的
Download Address:
It can also be obtained by other means, where I use the 1.8 version.
https://golang.org/dl/
Download the compressed package
# wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
Unzip the file, the default go path under/usr/local, create a go structure in/usr/local/go.
# tar -C /usr/local -xzvf go1.8.3.linux-amd64.tar.gz
You can see that the directory is already installed /usr/local/go :
# ls -l /usr/local/gototal 160drwxr-xr-x 2 root root 4096 May 25 02:15 api-rw-r--r-- 1 root root 33243 May 25 02:15 AUTHORSdrwxr-xr-x 2 root root 4096 May 25 02:16 bindrwxr-xr-x 4 root root 4096 May 25 02:16 blog-rw-r--r-- 1 root root 1366 May 25 02:15 CONTRIBUTING.md-rw-r--r-- 1 root root 45710 May 25 02:15 CONTRIBUTORSdrwxr-xr-x 8 root root 4096 May 25 02:15 doc-rw-r--r-- 1 root root 5686 May 25 02:15 favicon.icodrwxr-xr-x 3 root root 4096 May 25 02:15 lib-rw-r--r-- 1 root root 1479 May 25 02:15 LICENSEdrwxr-xr-x 14 root root 4096 May 25 02:16 misc-rw-r--r-- 1 root root 1303 May 25 02:15 PATENTSdrwxr-xr-x 7 root root 4096 May 25 02:16 pkg-rw-r--r-- 1 root root 1399 May 25 02:15 README.md-rw-r--r-- 1 root root 26 May 25 02:15 robots.txtdrwxr-xr-x 46 root root 4096 May 25 02:15 srcdrwxr-xr-x 17 root root 12288 May 25 02:15 test-rw-r--r-- 1 root root 7 May 25 02:15 VERSION
Adding environment variables
The go binary version will be installed /usr/local/go , but you can install the Go tool to another location. In this case, you must set the GOROOT environment variable to point to the installation directory.
To create the Gopath directory:
# mkdir -pv /app/gopath
Add this to the Global environment variable
# vim /etc/profile...export GOROOT=/usr/local/goexport PATH=$PATH:$GOROOT/bin
Save the file.
SOURCE re-reads the/etc/profile so that its configuration takes effect.
# source /etc/profile
Test
Review the version and check that the environment variables are correct:
# go versiongo version go1.8.3 linux/amd64
Check that go is installed correctly by setting up the workspace and building a simple program, as shown below.
# mkdir -pv /app/gopath/src/hello# cd /app/gopath/src/hello# vim hello.go
Code content is as follows
# cat hello.go hello.go package mainimport "fmt"func main() { fmt.Printf("hello, world\n")}package mainimport "fmt"func main() { fmt.Printf("hello, world\n")}
To build a program using the Go tool (compile packages and dependencies):
# go build# lltotal 1528-rwxr-xr-x 1 root root 1560062 Aug 12 10:08 hello-rw-r--r-- 1 root root 77 Aug 12 10:06 hello.go
The above command will build an executable named Hello in the directory next to your source code. Here we perform a look at the output:
# ./hello hello, world
You can now see the normal output ' Hello, world '.
The installation of the environment ends.