Golfing (Go Party) Development environment Setup and configuration

Source: Internet
Author: User

Official note, address Https://golang.org/doc/install

SDK Download

In the official website http://golang.org (may need to turn over the wall) directly download the corresponding operating system installation package installation. Here take the Mac as an example, download the PKG format of the latest installation package, run directly, follow the prompts to complete the installation.


The installation process is very simple


After the installation is complete, you can open the terminal and enter go to detect if the Golang SDK is successfully installed.

Enter Go version

When you see the display, it means success.


Environment variable Configuration

According to the official website, you need to configure the environment variables, the original content see:

The content is visible from the text (my English is not too good, if there are errors, laughed at), the default installation, the path is/usr/local/go. You only need to append/usr/local/go/bin to the environment variable path.

When customizing the installation path, add a goroot variable, point to the Custom installation path, and then append $goroot/bin after path, if it is a Windows system,%goroot%.

Working Space Workspace

Official text: https://golang.org/doc/code.html

A workspace is a directory hierarchy with three directories in its root:

SRC contains Go source files,

PKG contains Package objects, and

Bin contains executable commands.

Thus, the workspace should contain three directories, namely SRC (contains source file), Pkg (related package), bin (execution file).

The Go tool builds source packages and installs the resulting binaries to the PKG and bin directories.

The SRC subdirectory typically contains multiple version control repositories (such as for Git or Mercurial) this track th e Development of one or more source packages.

To give your idea of what a workspace looks in practice, here's an example:

The tree above shows a workspace containing the repositories (example and image). The example repository contains the commands (Hello and Outyet) and one library (stringutil). The image repository contains the BMP package and several others.

A Typical workspace contains many source repositories containing many packages and commands. Most go programmers keep all their Go source code and dependencies in a single workspace.

Commands and libraries is built from different kinds of source packages. We'll discuss the distinction later.

environment variable Gopath

The GOPATH environment variable

The GOPATH environment variable specifies the location of your workspace. It defaults to a directory named Goinside your home directory, so $HOME/go on Unix, $home/go on Plan 9, and%userprofile%\ Go (usually C:\Users\YourName\go) on Windows.

If you would a different location, you'll need to set Gopath to the path to the directory. (Another common setup is to set gopath= $HOME.) Note that Gopath must is the same path as your Go installation.

The command go ENV gopath prints the effective current gopath; It prints the default location if the environment variable is unset.

From the command go ENV gopath you can see the path that the current Gopath variable points to.

For convenience, add the workspace ' s bin subdirectory to your PATH:

For convenience, add the bin subdirectory of the workspace to the path

The scripts in the rest of this document is $GOPATH instead of $ (go env gopath) for brevity. The scripts run as written if you had not set Gopath, you can substitute $HOME/go in those commands or else run:

The scripts in the remainder of this article use $gopath instead of $ (go env gopath) to simplify. If you do not set Gopath, you can replace $home/go in these commands if you want the script to run as written, otherwise run

To learn more on the GOPATH environment variable, see ' Go help go path '.

To learn more about Gopath environment variables, see ' Go help go path '

To use a custom workspace location, set the GOPATH environment variable.

With a custom workspace location, you need to design gopath environment variables.

Gopath is used to tell Golang commands and other tools where to find the Go package directory on your system.

Gopath is a list of paths, similar to the settings for path

Gopath=/home/user/go:/home/user/workspace_go

Each list (path) is actually a workspace.

This is the official introduction of Gopath:

Https://golang.org/wiki/SettingGOPATH

Translation:

The GOPATH environment variable specifies the location of the workspace. If Gopath is not set, it is assumed to be $home/go on UNIX systems and%userprofile%\go on Windows. If you want to use a custom location as the workspace, you can set the GOPATH environment variable. This page explains how to set this variable on various platforms.

Note: The Gopath path cannot be the same as the Go installation path!

Unix Systems

Gopath can is any directory on your system. In Unix examples, we'll set it to $HOME/go (the default since Go 1.8). Note that Gopath must is the same path as your Go installation. Another common setup is to set gopath= $HOME.

Bash

Edit your ~/.bash_profile to add the following line:

Save and exit your editor. Then, source your ~/.bash_profile.

Zsh

Edit your ~/.ZSHRC file to add the following line:

Save and exit your editor. Then, source your ~/.ZSHRC.

Fish

The-x is used to specify the this variable should being exported and the-u makes this a universal variable, available to a ll sessions and persistent.

Windows

Your workspace can be located wherever I like, but we'll use the C:\go-work in this example.

Note: Gopath must not being the same path as your Go installation.

Create folder at C:\go-work.

Right click on "Start" and click on "Control Panel". Select "System and Security", then click on "System".

From the menu to the left, select the ' Advanced Systems Settings '.

Click the "Environment Variables" button at the bottom.

Click "New" from the "User variables" section.

Type Gopath into the "Variable name" field.

Type C:\go-work into the "Variable value" field.

Click OK.

Windows 10

There is a faster-to-edit environment Variables via search:

Left click on "Search" and type env or environment.

Select "Edit environment variables for your account".

... and follow steps above.

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.