顾名思义首先是安装Go,这里有很详细的安装说明, 或者(golang.org自己去找hosts),官方已经支持Windows版本
(1). 新建 变量名:GOBIN 变量值 :c:\go\bin
破解:
破解注册成功
同上输入GoSublime选择GoSublime回车
本机已经安装所以没有出现选项,输入Go build选中回车(这个属于可选)
到此GoSublime安装成功
打开控制台,输入以下内容:
go get github.com/nsf/gocode
go install github.com/nsf/gocode
go get github.com/DisposaBoy/MarGo
go install github.com/DisposaBoy/MarGo
安装完成后,我们可以在 go/bin 目录下,发现多出了个 gocode 文件.(一定要放在bin目录下)
"env": {"path":"c:/go/bin;" },
好了,到目前为止,开发环境搭建完成.
下面可以自由编程了.呵呵.
按下快捷键 Ctrl + b 界面下方会出现如下界面:
好了,到现在,开发环境就搭建完毕了.
如下是内容我这边没有使用照样可以使用:
tools-build system-new build system 新建一个配置文件 设置为
{
"cmd": ["go", "run", "$file_name"],
"working_dir": "$file_path",
"selector": "source.go"
}
然后就可以用ctrl+b 编译了
保存
MingW:
gocode 的github地址:
要安装git,在windows下,通常用msysgit.
再在cmd下安装:
go get -u github.com/nsf/gocode
(1).配置go的编译器
如果安装了MingW,可以在安装目录下找到gdb.
新建一个go工程,再建立一个hello.go.如下图:
gdb调试如下(要在console中用输入命令来调试):
目前这个eclipse插件,只能把代码放在cmd包中才能运行.
======================
<
Eclipse平台下配置Go语言开发环境步骤:
①.、安装JDK和Eclipse
安装完后重启Eclipse,并通过菜单项"Window"->>"Preferences"->>"Go"打开Go语言的配置选项框.如下图:
选择Go的安装路径即可,如笔者的安装路径是F:\Work\Go
安装完之后,通过菜单项"Window"->>"Preferences"->>"Go"->>"Debugger"打开调试器的配置选项框.
将GDB路径配置为:MinGW安装目录下的gdb.exe文件即可.
笔者使用的是goEclipse插件自带的版本,配置方式如下:
通过菜单项"Window"->>"Preferences"->>"Go"->>"Gocode"打开配置选项框.
将Gocode的路径配置为:goEclipse的安装路径下的gocode.exe文件,如
"fmt"
"github.com/astaxie/beedb"
_?"github.com/ziutek/mymysql/godrv"
为了编译该a.go文件,需要启动Console.bat,然后在该命令行窗口,进入c:\go\src目录下,执行go getgithub.com/astaxie/beedb
Go get github.com/ziutek/mymysql/godrv .
由于每一个Go程序都必须包含一个main包以及一个main()函数,所以呢如果没有main包就会导致上述错误.
What Doesn't Kill Me Makes Me Stronger
Go(又称 Golang)是 Google 的 Robert Griesemer,Rob Pike 及 Ken Thompson 开发的一种静态强类型、编译型语言.Go 语言语法与 C 相近,但功能上有:内存安全,GC(垃圾回收),结构形态及 CSP-style 并发计算.
go语言特点
go语言的应用领域
哪些公司(项目)在使用go语言
windows下安装
a.打开命令行
b. 输入$ go version
linux下安装
①在/usr/local/下面创建一个目录go
验证
①如果你的mac有Homebrew包管理工具,可以使用它来安装
开始安装
一路下一步就行了,没什么需要设置的,安装目录最好保持默认,避免遇到一些怪问题.
安装完成之后就可以打开命令行,看看安装成功了没有;
任意目录下,直接执行"go",能看到类似以下内容就对了:
或者执行:
[plain] view plain copy
C:\go?version
注意:我在安装完成之后执行"go"的时候就提示找不到文件或目录,我打开环境变量,在用户变量里加了一个PATH,
检查系统变量"PATH"中也有"C:\Go\bin",然后就在后面加了一个分号,确定保存之后再打开命令行就可以了,也不知道到底是哪个起作用了.
①1 Go 安装
Go的三种安装方式
Go有多种安装方式,你可以选择自己喜欢的.这里我们介绍三种最常见的安装方式:
Go源码安装:这是一种标准的软件安装方式.对于经常使用Unix类系统的用户,尤其对于开发者来说,从源码安装可以自己定制.
第三方工具安装:目前有很多方便的第三方软件包工具,例如Ubuntu的apt-get、Mac的homebrew等.这种安装方式适合那些熟悉相应系统的用户.
最后,如果你想在同一个系统中安装多个版本的Go,你可以参考第三方工具GVM,这是目前在这方面做得最好的工具,除非你知道怎么处理.
Go源码安装
在Mac系统中,只要你安装了Xcode,就已经包含了相应的编译工具.
在类Unix系统中,需要安装gcc等工具.例如Ubuntu系统可通过在终端中执行sudo apt-get install gcc
在Windows系统中,你需要安装MinGW,然后通过MinGW安装gcc,并设置相应的环境变量.
cd go/src
./all.bash
运行all.bash后出现"ALL TESTS PASSED"字样时才算安装成功.
上面是Unix风格的命令,Windows下的安装方式类似,只不过是运行all.bat,调用的编译器是MinGW的gcc.
如果是Mac或者Unix用户需要设置几个环境变量,如果想重启之后也能生效的话把下面的命令写到.bashrc或者.zshrc里面,
export GOPATH=$HOME/gopath
export PATH=$PATH:$HOME/go/bin:$GOPATH/bin
如果你是写入文件的,记得执行bash .bashrc或者bash
.zshrc使得设置立马生效.
如果是window系统,就需要设置环境变量,在path里面增加相应的go所在的目录,设置gopath变量.
当你设置完毕之后在命令行里面输入go,看到如下图片即说明你已经安装成功
图1.1 源码安装之后执行Go命令的图
如果出现Go的Usage信息,那么说明Go已经安装成功了;如果出现该命令不存在,那么可以检查一下自己的PATH环境变中是否包含了Go的安装目录.
关于上面的GOPATH将在下面小节详细讲解
Go标准包安装
Go提供了每个平台打好包的一键安装,这些包默认会安装到如下目录:/usr/local/go
(Windows系统:c:\Go),当然你可以改变他们的安装位置,但是改变之后你必须在你的环境变量中设置如下信息:
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
上面这些命令对于Mac和Unix用户来说最好是写入.bashrc或者.zshrc文件,对于windows用户来说当然是写入环境变量.
我们此时此刻呢的Go安装需要判断操作系统的位数,所以这小节我们先确定自己的系统类型.
Linux系统用户可通过在Terminal中执行命令arch(即uname
-m)来查看系统信息:
Mac 安装
看到类似上面源码安装成功的图片说明已经安装成功
如果出现go的Usage信息,那么说明go已经安装成功了;如果出现该命令不存在,那么可以检查一下自己的PATH环境变中是否包含了go的安装目录.
Linux 安装
假定你想要安装Go的目录为 $GO_INSTALL_DIR,后面替换为相应的目录路径.
$GO_INSTALL_DIR.
设置PATH,export PATH=$PATH:$GO_INSTALL_DIR/go/bin
然后执行go
Windows 安装
C:\Go\,若安装到其他位置会导致不能执行自己所编写的 Go 代码.安装完成后默认会在环境变量 Path 后添加 Go 安装目录下的 bin 目录
C:\Go\bin\,并添加环境变量 GOROOT,值为 Go 安装根目录 C:\Go\ .
验证是否安装成功
在运行中输入 cmd 打开命令行工具,在提示符下输入 go,检查是否能看到 Usage 信息.输入
cd %GOROOT%,看是否能进入 Go 安装目录.若都成功,说明安装成功.
不能的话请检查上述环境变量 Path 和 GOROOT 的值.若不存在请卸载后重新安装,存在请重启计算机后重试以上步骤.
第三方工具安装
GVM
gvm是第三方开发的Go多版本管理工具,类似ruby里面的rvm工具.使用起来相当的方便,安装gvm使用如下命令:
bash (curl -s -S -L )
安装完成后我们就可以安装go了:
执行完上面的命令之后GOPATH、GOROOT等环境变量会自动设置好,这样就可以直接使用了.
apt-get
Ubuntu是目前使用最多的Linux桌面系统,使用apt-get命令来管理软件包,我们可以通过下面的命令来安装Go,为了以后方便,应该把
git mercurial 也安装上:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:gophers/go
sudo apt-get update
sudo apt-get install golang-stable git-core mercurial
homebrew
homebrew是Mac系统下面目前使用最多的管理软件的工具,目前已支持Go,可以通过命令直接安装Go,为了以后方便,应该把
brew update brew upgrade
brew install go
brew install git
brew install mercurial
①.、编译vimgdb
mkdir -p ./tmp
cd tmp
安装依赖
sudo apt-get install build-essential
sudo apt-get build-dep vim-gtk
安装
// 这里直接执行make的操作
make
sudo make install
安装vimgdb runtime
cp vimgdb_runtime ~/.vim/bundle
打开vim
:helptags ~/.vim/bundle/vimgdb_runtime/doc " 生成doc文件
添加配置.vimrc
" vimgdb插件
run macros/gdb_mappings.vim
在vim中执行gdb时,报 "Unable to read from GDB pseudo tty" 的错误,因为没有安装 gdb ,所以安装gdb
sudo apt-get install gdb
set up vundle
$ git clone ~/.vim/bundle/vundle
Configure Plugins
在.vimrc文件的开头添加下面的内容,有些不是必须的,可以注掉
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)
" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'
" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from
Plugin 'FuzzyFinder'
" scripts not on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin ''
" ...
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" : PluginList - list configured plugins
" : PluginInstall(!) - install (update) plugins
" : PluginSearch(!) foo - search (or refresh cache first) for foo
" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Plugin commands are not allowed.
" Put your stuff after this line
Install Plugins
Launch vim and run
: PluginInstall
vim +PluginInstall +qall
Config vim file .vimrc,Add content bellow in bottom of the file
" 官方的插件
" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to
" reload them.
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
autocmd FileType go autocmd BufWritePre Fmt
配置go的环境变量,比如我的配置,GOPATH变量是必须要配置的,PATH中必须把GOPATH的bin也添加进去,否则没有自动提示,会提示找不到模式
export GOROOT=/usr/local/go
export GOPATH=/data/app/gopath
Set up gocode
go get -u github.com/nsf/gocode (-u flag for "update")
Configure vim in .vimrc file
Plugin 'nsf/gocode', {'rtp': 'vim/'}
写一个helloword程序,输入fmt后按C-xC-o如果能看到函数的声明展示出来,说明安装是正确的.
Set up godef
go get -v code.google.com/p/rog-go/exp/cmd/godef
go install -v code.google.com/p/rog-go/exp/cmd/godef
git clone ~/.vim/bundle/vim-godef
Bundle 'dgryski/vim-godef'
Set up gotags
go get -u github.com/jstemmer/gotags
Put the following configuration in your vimrc:
Bundle 'majutsushi/tagbar'
nmap :TagbarToggle
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
命令模式下按在右边就会显示当前文件下的函数名,结构体名等等,光标放到相应的tag上,按回车可以快速跳到程序中的相应位置.
再次按会关闭tag窗口.
PS:本地的.vimrc的配置
" 插件管理器 vundle
set nocompatible " be iMproved, required
filetype off " required
" Plugin 'tpope/vim-fugitive'
" Plugin 'Lokaltog/vim-easymotion'
" Plugin 'tpope/vim-rails.git'
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Plugin 'FuzzyFinder'
" Plugin 'git://git.wincent.com/command-t.git'
" Plugin ''
filetype plugin indent on " required
" filetype plugin on
" : PluginList - list configured plugins
" : PluginInstall(!)- install (update) plugins
" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins
" ********************************************************************
" 这里省略了其它不相关的插件
autocmd FileType go autocmd BufWritePre buffer Fmt
" 代码补全的插件
Bundle 'Blackrush/vim-gocode'
" 代码跳转提示
" 代码结构提示