Goroot, Gopath

Source: Internet
Author: User
Tags mkdir
Goroot is the Go installation path

Add the following statement in the ~/.bash_profile:

Goroot=/usr/local/go
Export Goroot

Of course, to execute the GO command and Go tool, you need to configure the path of the go executable file:
The operation is as follows:

The configuration in ~/.bash_profile is as follows:
Export Path:path:goroot/bin
If Windows needs to be used; the symbol splits two paths, Mac and Unix-like are separated by: symbol Gopath:

Go install/go get and go tools are used to gopath environment variables.
Gopath is the search path as the compiled binary storage destination and import package (in fact your working directory, you can create your own go source file under SRC and then start working).
Gopath consists of three main directories: bin, pkg, SRC

The bin directory mainly contains executable files; Pkg directory to store compiled library files, mainly *.a > pieces; The source files of go are mainly stored in the SRC directory.
Do not set the Gopath to the Go installation path,
You can create a directory yourself under the user directory, such as Gopath

The operation is as follows:

CD ~
mkdir Gopath

Add the following statement in the ~/.bash_profile:

Gopath=/users/username/gopath

Gopath can be a directory listing, go get download third-party library, will generally be downloaded to the first directory of the list
You need to configure the executable directory in the Gopath to the environment variable, otherwise the third-party go tool that you download yourself cannot be used, as follows:
Configured in ~/bash_profile,

Export $PATH: $GOPATH/bin

Create a Go project and compile and run:

mkdir Goproject
CD Goproject
Touch Hello.go
In the Hello.go, enter:
Package Main
Import "FMT"
Func Main () {
Fmt. Println ("Hello, GO!")
}

Execute the Go build command under the project root to build your project, and the build will generate a hello file
Run the generated file./hello, terminal output: Hello, GO!
Of course you can also run the command go running hello.go directly to execute the program.
If you want the above settings to take effect, you can execute the command: source ~/.bash_profile, all of the above actions are operating under the Mac system, and if it is a non-MAC system, make your own work.

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.