: Go install setup problem: Goroot,gopath

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

Using Google's official Go language installation package under Mac: Https://code.google.com/p/go/downloads/list installed go will automatically add the/usr/local/go/bin directory to the path. This allows us to execute some of the go language commands directly from the console.

http://golang.org/cmd/go/#hdr-gopath_environment_variablehttp://www.cnblogs.com/ghj1976/archive/2013/01/16/2863142.html

The binary compilation package for go assumes that you are installing go in/usr/local/go (or window is c:\Go) directory. Of course you can also install in other directories, but this time you need to set the Goroot environment variable. Http://golang.org/doc/install#install For example, if you install go in your/usr/local/go directory, you should $home/.profile file add the following settings.

export GOROOT=/usr/local/goexport GOPATH=$PATH:$GOROOT/bin

Execution: source. Bash_profile (Immediate effect)

Below the window is:

Under Windows, may set environment variables through the ' Environment variables ' button on the ' Advanced ' tab of T He "System" control panel. Some versions of Windows provide this control panel through the "Advanced system Settings" option inside the "SYSTEM" cont Rol panel.

For example, my Mac, in fact, I did not set goroot, but through the go env can get Goroot directory is:/usr/local/go

I guess this should be the default setting when there is no setting. If there is a setting, it is overwritten.

Gopath

Gopath's role is to tell the GO command and other related tools where to find the go package installed on your system.

Gopath is a list of paths, a typical gopath setting, similar to the path setting, win is separated by semicolons:

GOPATH=/home/user/ext:/home/user/mygo 

The path in each list is the location of a workspace. Each workspace has a source file, an object for the related package, and an execution file. Http://golang.org/doc/code.html

Here is a step to create a workspace:

Create the $HOME/mygo directory and the SRC directory as the source code.

mkdir -p $HOME/mygo/src # create a place to put source code 

The next step is to set up Gopath, and you should put the bin directory under this directory in the PATH environment variable so that you can execute directly at the command line without giving the full directory.

export GOPATH=$HOME/mygo export PATH=$PATH:$HOME/mygo/bin

Gopath must set up the compile and install package, that is, using the standard go directory tree, similar to the following:

GOPATH=/home/user/gocode/home/user/gocode/    src/        foo/            bar/               (go code in package bar) x.go quux/ (go code in package main) y.go bin/ quux (installed command) pkg/ linux_amd64/ foo/ bar.a (installed package object)

http://golang.org/cmd/go/#hdr-gopath_environment_variable

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.