Go language Learning

Source: Internet
Author: User
Tags lua gocode gotags

Installation of Ubuntu 14.04 GO Language compilation Environment 1. Using Ubuntu's library installation
sudo apt-get install golang

But there are a few bad places to install with Ubuntu libraries:

    • The Golang version is determined by the Ubuntu library, ubuntu14.04 currently offers Golang 1.2.1
    • The environment settings for the Golang language are already set by default, such as Goroot set to/usr/local/bin,gopath, etc.

It is recommended that you do not use Ubuntu libraries to install Golang environments

2. Install with Golang official documentation

Installation instructions for the Golang community Https://golang.org/doc/install

2.1 Uninstalling the ubuntu14.04 library installation Go
    • Uninstalling Golang-go

      sudo apt-get  remove golang-go
    • Uninstalling Golang-go and its dependencies

      sudo apt-get remove --auto-remove golang-go
    • Uninstall Golang-go and delete its local and configuration files

      sudo apt-get purge golang-go
    • Uninstall Golang-go and its dependencies and delete its local and profile files

      sudo apt-get purge --auto-remove golang-go
2.2 Installing with a compiled file
wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gztar -C /usr/local -zxf go1.6.2.linux-amd64.tar.gz

Set environment variables, modify the Etc/profile file so that the default search go location

export PATH=$PATH:/usr/local/go/bin

If go is installed in another location, add other locations to the path path

2.3 Test Go Installation

Set the work environment for go, modify the $home/.profile file

export GOPATH=$HOME/gowork

Test Hello-world

mkdir $HOME/gowork/src/hellocd $HOME/gowork/src/hello && touch hello.go

Enter the following code into HELLO.GO

package mainimport "fmt"func main() {    fmt.Printf("hello, world\n")}

Compiling and testing

go install hello$GOPATH/bin/hello
3. Vim Go Language Authoring Environment Configuration 3.1 vim go language syntax highlighting
  1. Because the Neocomplete plug-in requires vim7.4 and above, and requires vim to support Lua, the Ubuntu 14.04 Library-installed Vim does not support LUA, so it needs to be uninstalled and installed from the source code. Reference http://winter233.com/Using-Vim-with-Neocomplete/

    Uninstall the original Vim, if the original is not gvim, then the command removes Gvimsudo apt-get remove vim vim-runtime gvim//install vim dependent packages and tools, if you do not need the support of the desktop Environment (GVIM), Delete the gnome\gnomeui\libgtk\libatk\libbonoboui\libcairo\libx11\libxpm\libxt in the command, and if you use Git instead of Hg, delete the Mercurialsudo Apt-get Install Libncurses5-dev libgnome2-dev libgnomeui-dev libgtk2.0-dev libatk1.0-dev Libbonoboui2-dev Libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev ruby-dev mercurial//install luasudo apt-get Install liblua5.2-d EV lua5.2//compile Vim74 from source, if there is no desktop environment, you can delete the <--enable-gui=gtk2>wget ftp://ftp.vim.org/pub/vim/unix/ Vim-7.4.tar.bz2tar xvf vim-7.4.tar.bz2cd vim74./configure--with-features=huge--enable-multibyte--enable -rubyinterp--enable-pythoninterp--with-python-config-dir=/usr/lib/python2.7/config--enable-perl Interp--enable-luainterp--enable-gui=gtk2--enable-cscope--prefix=/usr//set vim74 rumtimedir, and Finis H installmake vimruntimedir=/usr/share/vim/vim74sudo make Install//check Installation by typing vim--version in shell Or:echo have ("Lua") in Vim. 
  2. Install Vundle, used to manage vim plugins, vundle on GitHub, Https://github.com/VundleVim/Vundle.vim

    git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

    Configure the. vimrc file in the $home directory and paste it from the link address (slightly)

  3. Install Vim-go, Vim's Go language plugin, https://github.com/fatih/vim-go modify the. vimrc file, add the following:

    Plugin ‘fatih/vim-go‘
  4. Vim-go to fully work, you also need some necessary tools (such as Gocode, Godef, Goimport etc), which can be installed via Vim's :GoInstallBinaries command, if previously installed, can be :GoUpdateBinaries updated, This will allow tools such as Gocode to be installed in the $gopath/bin directory.

  5. Install Neocomplete.vim, Https://github.com/Shougo/neocomplete.vim This is the vim-go recommended real-time auto-complete plug-in

    Plugin ‘Shougo/neocomplete.vim‘
  6. Install Ctags + gotags + tagbar, where Ctags compatible gotags is used because Ctags does not support go.

    Install Ctagswget http://prdownloads.sourceforge.net/ctags/ctags-5.8.tar.gztar-zxf CTAGS-5.8.TAR.GZCD ctags & &./configure && make && make install//install gotags, see Gotags githubgo get-u github.com/jstemmer/ gotags//add config to. vimrc for tagbarlet g:tagbar_type_go = {\ ' ctagstype ': ' Go ', \ ' kinds ': [\ ' P :p ackage ', \ ' i:imports:1 ', \ ' c:constants ', \ ' v:variables ', \ ' t:types ', \ ' N:interfa    Ces ', \ ' w:fields ', \ ' e:embedded ', \ ' m:methods ', \ ' r:constructor ', \ ' f:functions ' \], \ ' SRO ': '. ', \ ' kind2scope ': {\ ' t ': ' CType ', \ ' n ': ' Ntype ' \}, \ ' Scope2kind ': {\ ' ctype ': ' t ', \ ' ntype ': ' n ' \}, \ ' Ctagsbin ': ' gotags ', \ ' Ctagsargs ': '-sort-silent ' \ }//install tag using vundle Plugin ' majutsushi/tagbar '//add config to. vimrc for quick Start, see Tagbar Githubnmap in detail Gt :tagbartoggle<cr>
  7. After the vim is configured, the terminal needs to be re-logged in order to take effect.

Go language Learning

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.