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
Package Main
Import "FMT"
Func Main () {
Fmt. Println ("Hello World")
}
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
_________________________________________________________________
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
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 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
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.