Installing Go1.6 from source code to CentOS 7

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

Install Go1.6 from source code to CentOS 7 in China network environment

Https://github.com/northbright/Notes/blob/master/Golang/china/install-go1.6-from-source-on-centos7-in-china.md

Background

    • In the current Chinese network environment, we are unable to access Google's services, including golang.org.
    • Downloading a precompiled binary go release from a third-party website may present a risk of third-party source code injection, such as previous xcodeghost.
    • GoThe authoritative warehouse address is https://go.googlesource.com/go, and there is also a mirrored warehouse in Https://github.com/golang/go.
    • At least for now, we have access to GitHub:-)

Problem

    • The Go1.6 compilation process requires the Go1.4 of the two in the implementation of Bootstrap (bootstrap) (simply: go requires go itself to compile).

Solution Solutions

    • Get the source code for go from GitHub's Go warehouse image.
    • First compile the Go1.4 (only need gcc and glibc-devel , do not need go to compile).
    • Compile the Go1.6 using a compiled Go1.4 binary file.

Steps

  1. If you have previously installed the old version of Go, clear the $GOPATH, $GOROOT variable.

  2. Install Git.

    • ConfigurationGit
      • git config --global user.email "email-for-github"
      • git config --global user.name "user name"
    • Create SSH key and add public key to your GitHub account.
      • ssh-keygen -t rsa -b 2048
      • Copy ~/.ssh/id_rsa.pub the public key to GitHub SSH settings to add a new SSH key
  3. Installation gcc andglibc-devel

    • sudo yum install gcc glibc-devel
  4. Compiling from source code install Go1.4

    • cd ~/
    • git clone git@github.com:golang/go.git
    • cd go
    • git checkout -b 1.4.3 go1.4.3
    • cd src
    • ./all.bash
  5. Copy ~/go to $GOROOT_BOOTSTRAP (default value is ~/go1.4 )

    • cp ~/go ~/go1.4 -rf
  6. Compiling from source code install Go1.6

    • cd ~/go
    • git clean -dfx
    • git checkout -b 1.6 go1.6
    • cd src
    • ./all.bash
  7. Set up $GOPATH and add go binary path to$PATH

    • sudo vi /etc/profile

        # Golang Env  export PATH=$PATH:/home/xx/go/bin  export GOPATH=/home/xx/go-projects
  8. Restart and test

    • sudo reboot
    • go version

        go version go1.6 linux/amd64

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.