首页 > 代码库 > Install golang on Ubuntu 14.04 LTS

Install golang on Ubuntu 14.04 LTS

1. Install golang on Ubuntu 14.04 LTS

a)~$ sudo apt-get install golang                   success

b)~$ sudo add-apt-repository ppa:gophers/go

   ~$ sudo apt-get update

   ~$ sudo apt-get install golang-stable         fail

c) complie from source code                        fail to download source code, fuk GFW

 

2. Version of golang

~$ go version

go version go1.2.1 linux/amd64

 

3. Default env of golang

~$ go env
GOARCH="amd64"  
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"

Someone said that:

"You don‘t need to set GOROOT, really." 

http://dave.cheney.net/2013/06/14/you-dont-need-to-set-goroot-really

In another go doc page:

"The GOPATH environment variable specifies the location of your workspace. It is likely the only environment variable you‘ll need to set when developing Go code." 

Here is the discuss about GOROOT and GOPATH.

http://stackoverflow.com/questions/7970390/what-should-be-the-values-of-gopath-and-goroot

 

4. Set Vim for golang

Here is the most common way.

a) ~$ cp -r $GOROOT/misc/vim/* ~/.vim/                                // I can‘t find ‘/misc/vim/*‘. It may not exist now.

b) Attend follow commands in ~/.vimrc. If ~/.vimrc doesn‘t exist, create it.

filetype plugin indent on

syntax on                         // I feel very confused about how to add golang syntax highlighting for vim.

c) install Gocode

 

Here is my way.

a) Install Vundle

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

If ~/.vim/bundle/vundle doesn‘t exist, create it.

b) Add following commands to the head of ~/.vimrc.

set nocompatible               " be iMproved
filetype off                   " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required! 
Bundle gmarik/vundle
filetype plugin indent on
syntax on

c) Install vim-go

~$ sudo apt-get install mercurial
~$ cd ~/.vim/bundle
~$ git clone https://github.com/fatih/vim-go.git

Add this line to ~/.vimrc.

Plugin fatih/vim-go

Execute :PluginInstall in Vim.                                                     // Fail to connect google service. Fuk GFW!

d) Install Gocode

~$ go get -u github.com/nsf/gocode
~$ cd $GOPATH/src/github.com/nsf/gocode/vim
~$ ./update.bash
~$ gocode set propose-builtins true
~$ gocode set lib-path "$GOPATH/pkg/linux_amd64"

May be enough for beginners.

 

Reference

fatih/vim-go

https://github.com/fatih/vim-go

nsf/gocode

https://github.com/nsf/gocode

set vim for golang (Chinese)

http://ju.outofmemory.cn/entry/49172

 

Let‘s have fun!