Install golang on Ubuntu 14.04 LTS

senjougahara · · 8831 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

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!

本文来自:博客园

感谢作者:senjougahara

查看原文:Install golang on Ubuntu 14.04 LTS

8831 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传