Ubuntu Install go:

Source: Internet
Author: User
Tags install go gocode

Ubuntu Install go:


sudo add-apt-repository ppa:gophers/go
sudo apt-get update
sudo apt-get install golang-stable

Method Two:

sudo apt-get install Golang

Method Three:

Download the Go language installation package directly

Environment configuration:
Vi/etc/profile
Join
Export Goroot=/usr/lib/go
Export goarch=386
Export Goos=linux
Export Gopath=/home/gopath
Export gobin= $GOPATH/bin
Export path= $GOPATH/bin: $PATH

Note

Recommended Terminal installation VIM Editor:

$ sudo apt-get install vim)

You want to take the input immediately after saving

Source/etc/profile


Create a new three directory under new Gopath
mkdir src Pkg Bin
SRC Storage Source
Pkg to store compiled generated files
Bin holds the resulting executable file

Create your first Go app
CD $GOPATH/SRC
mkdir test1
CD Test1
VI Test.go

    1. Package Main

    2. Import "FMT"

    3. Func Main () {

    4. Fmt. Println ("Hello World")

    5. }

Main.main () is the entrance to the Go app

Compilation method
1, enter the corresponding application package directory, and then perform go install, you can install the
2. Execute the following code in any directory go install test
3, enter the corresponding application package directory, and then execute go build, will generate the executable file in the current directory

Note: Some simple uses of vim (can not be used)

Configure VIM to support go language syntax highlighting
Cp-r $GOROOT/misc/vim/* ~/.vim/Note: $GOROOT is the Go installation directory
VI ~/.VIMRC Join
FileType plugin indent on
Syntax on

Installing Gocode

Go get-u github.com/nsf/gocode
The Gocode is installed by default under $gobin.

Configure Gocode

~ CD $GOPATH/src/github.com/nsf/gocode/vim
~./update.bash
~ Gocode Set Propose-builtins True
Propose-builtins true


_________________________________________________________________


    1. Goroot is the Go installation path
      Add the following statement in the ~/.bash_profile:

Goroot=/usr/local/goexport 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:$GOROOT/bin
If Windows needs to use ; symbols to split two paths, both Mac and Unix-like are separated by a : symbol

    1. 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).

      1. Gopath consists of three main directories: bin, pkg, SRC

      2. The bin directory mainly contains executable files; Pkg directory to store compiled library files, mainly *.a files; 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 list of directories, go get downloaded third-party libraries, 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 GOPROJECTCD Goprojecttouch Hello.go

In the Hello.go, enter:

Package Mainimport "FMT" Func Main () {FMT. Println ("Hello, GO!")}

Execute commands under the project root go build to build your project, build a Hello file
Run the generated file ./hello , output in terminal:Hello, GO !
Of course you can also run the command directly go run hello.go to execute the program.

If you want the above settings to take effect, you can execute the command: All of the source ~/.bash_profile above actions are actions under the Mac system, and if they are non-MAC systems, make your own.



Author: Yuan Henry Zhen O
Links: Https://www.jianshu.com/p/4e699ff478a5
Source: Pinterest
The copyright of the book is owned by the author, and any form of reprint should be contacted by the author for authorization and attribution.



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.