Go Language Introductory Tour (ii): Environmental construction-linux

Source: Internet
Author: User

A Golang small white study notes, hope to learn together with you, write a bad place, please correct me, thank you! ~

Although we generally develop on the Windows operating system, the general online production server system is Linux, so familiarity with the installation of the Go language on Linux is also a skill that go beginners must master.

The official Go Language website provides us with a binary installation package for the Linux operating system that can be installed very simply, in addition to using binary, different Linux distributions also offer different third-party installation tools, such as CentOS Yum and Ubuntu Apt-get.

Installation

1. Binary package installation (recommended)

Depending on whether your computer is a 32-bit or 64-bit download of the corresponding installation package, for example, I downloaded a 64-bit,

wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz //使用wget命令下载安装包tar -zxvf -C /usr/local/go  go1.10.3.linux-amd64.tar.gz //解压到/usr/local/go目录

2. Yum Installation

sudo yum install go

3. Apt-get Installation

sudo apt-get install golang

Configuring Environment variables

export GOROOT=/usr/lib/goexport GOARCH=386 //处理器加构,如果是64位的,应改为amd64export GOOS=linuxexport GOPATH=/home/gopathexport GOBIN=$GOPATH/binexport PATH=$GOPATH/bin:$PATH

1. Goroot

Goroot points to the install directory of Go.

2. Gopath

Workspace, divided into three directories by specification: Src,pkg,bin
The general Gopath directory is as follows

$GOPATH  bin/      main.exe  pkg/      windows_amd64            lib.a  src/          main.go          lib              lib.go

Enter the GO command at the Terminal command line and the result is as follows to indicate the configuration was successful

$ goGo is a tool for managing Go source code.       Usage:go command [arguments]the commands are:build compile packages and dependencies clean Remove object files Doc show documentation for package or symbol env print Go environmen T information bug start a bug report fix run Go tool fix on packages FMT run  GOFMT on package sources generate generate Go files by processing source get download and install Packages and dependencies install compile and install packages and Dependencies list List Packag         Es run compile and run Go Program test test Packages Tool run specified Go tool Version print Go version vet run Go tool vet on Packagesuse ' Go help [command] ' for more inform ation about a command. Additional help Topics:c calling between Go and C BuilDmode description of build modes filetype file types Gopath gopath environment variable env        Ironment Environment Variables Importpath Import path Syntax packages description of package lists Testflag Description of testing flags TestFunc description of testing FunctionsUse "Go help [topic]" For MO Re information about that topic.

First Go Language Program

Create a new Main.go file in the src directory of Gopath, with the following code

package mainimport "fmt"func main(){  fmt.Println("Hello World")}

Run

$ go run main.goHello World

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.