Build the Go development environment from source code

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

Build the Go development environment from source code

Previous versions of Go 1.5

Install the C language development environment

Before go 1.5 versions (such as 1.3, 1.4), will be partially dependent on the C language toolchain, so if you have a C language development environment, you can directly build the Go development environment. If you do not have a C language development environment, install the C language development environment first.

7 Yum Install GCC

Set up directory structure for Go

The basic directory is like this

$HOME/Golang|--3rd|--go|--own

Because we have to install the version after Go 1.5, we need backwards compatibility, so we need to modify the directory. Add a version directory. And point go to the Go version directory we are currently using. The modified directory structure is as follows:

$HOME/Golang|--3rd|--go-Go1. 4|--go1. 4|--own

The go directory at this point is a soft link, pointing to go1.4. I use the download good Go source to install, so first extract the source code into the go1.4 directory.

Environment variables

Gopath= $HOME/golang/3rdpkg: $HOME/golang/go: $HOME/golang/own

In this configuration, when you use go get to get the go package, you first import the first path to the $GOPATH, which is the 3rdpkg directory. It makes it easy to separate third-party packages from their own projects.

Set Goroot

goroot= $HOME/golang/go

Set the PATH variable

Path= $PATH: $GOROOT/bin/

At this point the complete environment variable is set to

Gopath= $HOME/golang/3rdpkg: $HOME/golang/go: $HOME/golang/owngoroot= $HOME/golang/gopath= $PATH: $GOROOT/bin

Install Go 1.4

CD $HOME/golang/go/src. /all.bash

After the execution is complete, go 1.4 is deployed.

Version after Go 1.5

Both the Go 1.5 and later versions removed dependency on the C language, instead using go to compile the new Go language version. So our directory structure needs to be changed and let go 1.4来 help us build a new go environment.

Because our goal is the version after Go 1.5, so 1.6, 1.7 are applicable, knot down we compile the latest go 1.7 environment. So our directory structure is like this:

$HOME/Golang|--3rd|--go-Go1. 7|--go-bootstrap, Go1. 4|--go1. 4|--go1. 7|--own

Environment variables are also modified accordingly.

Gopath= $HOME/golang/3rdpkg: $HOME/golang/go: $HOME/golang/owngoroot= $HOME/golang/gopath= $PATH: $GOROOT/Bingoroot_bootstrap= $HOME/golang/go-bootstrapcd $HOME/golang/go/src. /all.bash

Refer here

Sync posted here: Http://www.fengbohello.xin3e.com/blog/p/golang

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.