Linux under 64-bit precompiled go 1.6.2 installation

Source: Internet
Author: User
Tags mercurial
This is a creation in Article, where the information may have evolved or changed.

Go Installation-1.6.2


OS: Linux, 64-bit, Readhat 7.2

Pre-compiling GZ package installation using official website


1. URL https://golang.org/
Current version 1.6.2


download page https://golang.org/dl/


https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz




2. Unzip
Go Requirements ROOTdirectory in/usr/local, unzip the command:
[root@ip-172-30-0-110 home]# tar-c/usr/local-xf go1.6.2.linux-amd64.tar.gz
[root@ip-172-30-0-110 home]# ls/usr/local/
bin etc Games go include Lib lib64 libexec sbin share src




3. Modify/etc/profile Add as follows:
Export Goroot=/usr/local/go
Export path= $GOROOT/bin: $PATH



Source/etc/profile


Test
[root@ip-172-30-0-110 go]# which go
/usr/local/go/bin/go


[root@ip-172-30-0-110 go]# go version
Go version go1.6.2 linux/amd64
[root@ip-172-30-0-110 go]#




4. Running the HelloWorld program
Hello.go Content


Package Main
Import "FMT"


Func Main () {
Fmt. Printf ("Hello world!\n");
}



Compile Run
[root@ip-172-30-0-110 go]# VI hello.go
[root@ip-172-30-0-110 go]# go run hello.go
Hello world!
[root@ip-172-30-0-110 go]#




5. Compiling the Hello Project
under current directory, create a directory
[root@ip-172-30-0-110 gopath]# mkdir bin pkg src
[root@ip-172-30-0-110 gopath]# ls
bin pkg src
Place the file as follows
[root@ip-172-30-0-110 gopath]# tree.
.
├──bin
├──pkg
└──src
└──hello
└──hello.go


in the current directory, compile the Hello project
[root@ip-172-30-0-110 gopath]# export gopath= ' pwd '; go install hello
[root@ip-172-30-0-110 gopath]# tree.
.
├──bin
│└── Hello
├──pkg
└──src
└──hello
└──hello.go


4 directories, 2 files
[root@ip-172-30-0-110 gopath]#


Run the executable file
[root@ip-172-30-0-110 gopath]# Bin/hello
Hello world!
[root@ip-172-30-0-110 gopath]#


Description:
a) Go to find a package in two places
src directory under $GOROOT, and the SRC directory under $GOPATH


An example of this error is:
[root@ip-172-30-0-110 gopath]# go install hello.go
Go install:no install location for. Go files listed in command line (GOBIN not set)


[root@ip-172-30-0-110 gopath]# go install hello
can ' t load package:package hello:cannot Find package "Hello" in any of:
/usr/local/go/src/hello (from $GOROOT)
( $GOPATH not set)



b) The name of the project can be changed,
If you change Src/hello to test, then the name of the project becomes test, such as using the Go Build command, as follows:
[root@ip-172-30-0-110 gopath]# go Build test
[root@ip-172-30-0-110 gopath]# ls-alht
Total 2.2M
drwxr-xr-x 5 root root 03:01 June 6.
-rwxr-xr-x 1 root root 2.2M June 6 03:01 test
drwxr-xr-x 2 root root 6 03:00 bin
drwxr-xr-x 3 root root 6 02:54 src
drwxr-xr-x 2 root root 6 June 6 02:43 Pkg
drwxr-xr-x. 7 root root 4.0K June 6 02:41.
[root@ip-172-30-0-110 gopath]#
directory Structure
.
├──bin
├──pkg
├──src
│└──test
│└──hello.go
└── Test





6. Mercurial Tools
Yum Install mercurial
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.