Go language - Start

Reference website, https://golang.google.cn/doc/install

This page explains in detail Golang download, system requirements, and installation, basic test methods

system requirement

Before you run the Go language, see the table below

operating system Architecture Remark

FreeBSD 10.3 or later amd64, 386 Does not support Debian GNU / kFreeBSD 
Linux with the glibc 2.6.23 or later amd64, 386, arm, arm64,
s390x, ppc64le
Does not support CentOS / RHEL 5.x
macOS 10.10 or update amd64 Use with Xcode ‡  the gcc or Clang  support cgo 
Windows 7, Server 2008R2 or newer amd64, 386 Use MinGW ( 386) or W64-MinGW ( amd64) GCC .
Not require cygwin or msys.

Only if you intend to use the  CGO , it needs  AC compiler
that you only need to  Xcode  install command-line tool

Installation GoLang

If you need to upgrade GoLang originally from a previous version, you must remove the previously existing version

Linux, macOS, and FreeBSD tarballs

Download and unzip the file into the directory  /usr/local, the directory /usr/local/go 中建立一个树形目录 例如:

tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

Select the appropriate file package to perform your installation. For example, if you are 64-bit Linux systems to install the 1.2.1 version of the Go language, file pack you need to call is 

go1. 2.1 In order linux-amd64. tar gz

(In general, the implementation of these commands require root user or by  sudo 获取root权限)

Add Directory  /usr/local/go/bin 到环境变量

By adding the following instruction to the directory  /etc/profile (the system level installation) or to the directory  $HOME/.profile:

export PATH=$PATH:/usr/local/go/bin

Note : To  profile modify this file may not take effect once sign in front of your system in your next order for these changes to take effect immediately, run shell commands or call directly from the profile, similar to the following instructions.

source $HOME/.profile

macOS package installation

Download and open the package, along with the option to install Go tools. This package will be distributed to the installation directory Go /usr/local/go

This package will direct the directory  /usr/local/go/bin to add to your environment variables. You only need to restart your terminal, to take effect

Windows System

Go project provides two options for Windows users (in addition to installing from source): a need to set environment variables of its own zip archive and a good MSI installer automatically configured

MSI Installer

Open the MSI file and follow the installation options Go tools. The installation will default installation directory is distributed to Go C:\Go

The installer will put your C: \ Go \ bin to your PATH environment variable, you just need to restart the exercise of command changes to take effect

Zip archive

Download the zip installation package and extract it to the directory of your choice (we recommend C: \ Go)

Add a bin subdirectory Go to your root directory (for example, C: \ Go \ bin) to your PATH environment variable

Set the environment variable in Windows

In Windows, you can "System" control disk "Adanced" tab in the "Environment Variables" button to set environment variables. Some windows versions provided by the control panel "Advanced System Settings" option

Testing your installation.

Go check is successfully installed, you can be like the next by setting a workspace and build a simple program

Create your workspace directory% USERPROFILE% \ go (if you want to use a different directory, you need to set environment variables)

Next, create your workspace in a directory src \ hello, create a file called hello.go in the directory, as follows:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

Then build with tools Go

C:\> cd %USERPROFILE%\go\src\hello
C:\Users\Gopher\go\src\hello> go build

The above command will create an executable file called hello.exe according to the source folder

See the following greeting After calling

C:\Users\Gopher\go\src\hello> hello
hello, world

If you see a "hello, world" information to show that you have worked to install

You can run go install 指令安装二进制到你的工作空间的 bin 目录或者 go clean -i 指令来移除它

Go before you rush to write the code, please read the documentation, a detailed description of the use of tools Go important concepts

Go install other versions

In the same Go and install multiple versions may be useful, for example, in order to ensure a package can pass the test multiple versions of Go in. Once a Go version installed, you can install another version (for example, 1.10.7), like the following instruction:

$ go get golang.org/dl/go1.10.7
$ go1.10.7 download

Download the new version can run something like this

$ go1.10.7 version
go version go1.10.7 linux/amd64

Go all the available versions are listed on the download page by this method

Each additional version will be downloaded to Go looks GOROOT directory, for example go1.10.7 env GOROOT

To uninstall a version has been downloaded, just remove the directory and its GOROOT binary go.XYX

Uninstall Go

Go to remove the installation already present in the system deleted Go directory, usually under Linux, macOs and FreeBSD / usr / local / go, and C under Windows: \ Go directory

Go also need to be removed from the bin directory in the PATH environment variable, Linux and FreeBSD, you should edit  /etc/profile or $HOME/.profile 文件

If macOS, need to remove the  /etc/paths.d/go file

Guess you like

Origin www.cnblogs.com/YC-L/p/12150422.html