资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

mac下go语言环境配置,mac 安装go

如何在Mac源码安装Go1.5开发环境

Go1.5开发环境依赖Go1.4版本作为引导,因为Go1.5使用Go本身来编译安装Go,所以必须保证服务器上已经安装Go1.4,这完全是为了解决先有鸡还是先有蛋的问题,当然如果你想避免编译安装1.4也可以直接使用二进制包。

创新互联建站主要为客户提供服务项目涵盖了网页视觉设计、VI标志设计、成都全网营销推广、网站程序开发、HTML5响应式重庆网站建设手机网站开发、微商城、网站托管及成都企业网站维护、WEB系统开发、域名注册、国内外服务器租用、视频、平面设计、SEO优化排名。设计、前端、后端三个建站步骤的完善服务体系。一人跟踪测试的建站服务标准。已经为假山制作行业客户提供了网站改版服务。

在这里假设你希望将go1.5安装到$HOME/go1.5目录下,只需要以下几步:

下载Go1.5的源码放到$HOME/go1.5目录下

在安装Go1.5之前需要将Go1.4放到$HOME/go1.4下面或者export GOROOT_BOOTSTRAP=/go1.4安装目录/

到$HOME/go1.5/src/下执行all.bash即可

我习惯将软件安装至/usr/local/下,以下为我安装Go1.5(/usr/local/go1.5)的步骤:

wget

tar zxvf go1.5.1.src.tar.gz

mv ./go /usr/local/go1.5

wget

tar zxvf go1.4.3.src.tar.gz

mv ./go /usr/local/go-bootstrap1.4/

cd /usr/local/go-bootstrap1.4/src

./all.bash //编译安装Go1.4,有可能test不通过,只要编译通过,test可忽略,目的是需要go1.4的二进制包来编译1.5

cd /usr/local/go1.5/src

GOROOT_BOOTSTRAP=/usr/local/go-bootstrap1.4 ./all.bash

//可在环境变量中添加GOROOT_BOOTSTRAP,然后再编译Go1.5

以下为网摘:

From C to Go

The gc tool chain is being converted from C to Go.

An ongoing process, started early 2014.

Russ Cox says "It'll be done by March [2015]."

New link tool to replace 6l, 8l, etc.

New asm tool to replace 6a, 8a, etc.

Machine-translated gc to replace 6g, 8g, etc.

Design doc:

golang.org/s/go13compiler

Go 1.5 will have no C code in the tool chain or runtime.

Go语言将使用Go代替C重写运行时环境

Go 1.4 的合并窗口在 9 月份将关闭,从现在开始到12月份发布 Go 1.4 之前将只接受 bug 修复和小调整。

Go 1.4 最主要的变化是将使用 Go 语言本身来重写 Go 的运行时,而之前是采用 C 语言开发。这也是为什么 Go 的发行版中包含一个 C

编译器的原因。

使用 Go 重写的好处是:

当前如果在 Goroutine 的调用堆栈中发现 C 代码,runtime 将在需要增长堆栈时回滚到老的堆栈方法。如果使用 Go 来重写

runtime,那么堆栈拷贝的方法就会更加高效

目前转换工作只计划转 Go 编译器 (5g, 6g, 8g), 而不是 C 编译器,降低运行时中的 C 代码行数,甚至可能完全清除

注意

这是 golang.org 分发版,也就是 gc ,而不是 gccgo

这是不同的 C 编译器,gc 工具链将使用你系统的 C 编译器来编译,gc 运行时则使用它的 C 编译器来编译

8月20日后增加的转换行可能跟 this request 有关.

Go语言将使用Go代替C重写运行时环境

— 从现在开始到12月份 Go 1.4版本发布前,Go将只接受Bug修复和小范围的调整,Go

1.4版本将实现使用Go语言来重写Go的运行时环境。

如何配置go语言集成开发环境 vim

1、编译vimgdb

下载vimgdb73和vim73

mkdir -p ./tmp

cd tmp

tar zxvf ../vim-7.3.tar.gz

unzip ../vimgdb-for-vim7.3-master.zip

mv vimgdb-for-vim7.3-master vimgdb-for-vim7.3

patch -p0 vimgdb-for-vim7.3/vim73.patch

cd vim73

安装依赖

sudo apt-get install build-essential

sudo apt-get build-dep vim-gtk

sudo apt-get install libncurses5-dev

安装

// 这里直接执行make的操作

make

sudo make install

安装vimgdb runtime

cd ../vimgdb-for-vim7.3

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

2、安装vundle

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 'L9'

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

3、官方vim-lang插件

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

4、代码补全的插件gocode

配置go的环境变量,比如我的配置,GOPATH变量是必须要配置的,PATH中必须把GOPATH的bin也添加进去,否则没有自动提示,会提示找不到模式

export GOROOT=/usr/local/go

export GOPATH=/data/app/gopath

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Set up gocode

Then you need to get the appropriate version of the gocode, for 6g/8g/5g compiler you can do this:

go get -u github.com/nsf/gocode (-u flag for "update")

Configure vim in .vimrc file

Plugin 'nsf/gocode', {'rtp': 'vim/'}

Install Plugins

Launch vim and run

: PluginInstall

vim +PluginInstall +qall

写一个helloword程序,输入fmt后按C-xC-o如果能看到函数的声明展示出来,说明安装是正确的。

4、代码跳转提示godef

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

Configure vim in .vimrc file

Bundle 'dgryski/vim-godef'

Install Plugins

Launch vim and run

: PluginInstall

vim +PluginInstall +qall

5、代码结构提示gotags

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' : '.',

\ 'kind2scope' : {

\ 't' : 'ctype',

\ 'n' : 'ntype'

\ },

\ 'scope2kind' : {

\ 'ctype' : 't',

\ 'ntype' : 'n'

\ },

\ 'ctagsbin' : 'gotags',

\ 'ctagsargs' : '-sort -silent'

\ }

命令模式下按在右边就会显示当前文件下的函数名,结构体名等等,光标放到相应的tag上,按回车可以快速跳到程序中的相应位置。

再次按会关闭tag窗口。

PS:本地的.vimrc的配置

" 插件管理器 vundle

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 'L9'

" 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

syntax on

" ********************************************************************

" 这里省略了其它不相关的插件

" vimgdb插件

run macros/gdb_mappings.vim

" 官方的插件

" 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 buffer Fmt

" 代码补全的插件

Bundle 'Blackrush/vim-gocode'

" 代码跳转提示

Bundle 'dgryski/vim-godef'

" 代码结构提示

Bundle 'majutsushi/tagbar'

nmap F8 :TagbarToggleCR

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' : '.',

\ 'kind2scope' : {

\ 't' : 'ctype',

\ 'n' : 'ntype'

\ },

\ 'scope2kind' : {

\ 'ctype' : 't',

\ 'ntype' : 'n'

\ },

\ 'ctagsbin' : 'gotags',

\ 'ctagsargs' : '-sort -silent'

\ }

如何配置go语言开发环境

1、下载go的zip文件。并且一定要把文件解压到c:\go目录下。

2、配置windows的高级环境变量。包括:GOROOT、GOOS、GOBIN、GOARCH。并且在path变量里面把c:\go\bin加入。以便可以在命令行直接运行go命令。

举例:我的机器:

GOPATH= c:\go;c:\go\src;F:\workspace\goSample01;

GOBIN=c:\go\bin;F:\workspace\goSample01\bin;

其中,c:\go是go的安装路径;

F:\workspace\goSample01是我写的go语言项目的工程目录;

F:\workspace\goSample01\bin是go语言项目的工程目录下的可执行文件路径;

3、在完成环境变量配置后,打开一个命令行窗口,直接输入go,然后回车,看看是否出现go的帮助信息。如果出现,那么go的基本环境就OK了。

注意:这个基本环境不包含开发工具,也不能直接编译带C代码的go程序。

4、(可选)为了支持Import远程包,最好装个gomingw。下载地址:。如果下的是压缩包,请把它解压到C盘。例如,C:\gowin-env。里面有个Console.bat是以后使用go get的环境。举例:有个文件a.go,里面import(

"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会自动下载该远程包并编译和安装这些包。

配置goclipse(可选)

(如果不喜欢eclipse开发工具,请跳过这个配置。)

1、下载并安装goclipse插件。Goclipse是go语言for eclipse的插件,下载地址:

2、启动eclipse并创建go项目。然后写个最简单的helloworld.go文件,并运行。代码如下:

packagemainimport"fmt"func main(){ fmt.Printf("hello, world")}

配置gocode(可选)

如果不需要go语法辅助和eclipse里面的(按ALT+/)弹出go语言自动辅助功能,请跳过这个配置。

1、下载gocode的zip文件,解压后放在go的bin目录下。

2、下载并安装Git软件。并且在path里面配置git的执行路径。例如c:\git\bin

3、在命令行执行:go build .\gocode。如果一切正常,那么将会编译生成一个gocode.exe文件在go的bin目录下。如果编译失败,那么就转第4步。

4、如果第3步直接编译gocode源文件成功,那就直接到第5步。否则,就需要通过git下载gocode源文件,然后再编译。在命令行执行:go get -u github.com/nsf/gocode 。就会生成gocode.exe文件。

5、在goclipse插件里面指定gocode的路径。就可以在elcipse里面调用gocode来帮助写编码了。

从开发工具这块看,go语言还不够成熟,开发工具都还不完善,有待改进。

下载go-tour教程源代码(可选)

Google有个在线运行go语言的教程(),很不错。支持在web上直接运行大部分的go程序,想了解这个教程的源代码的朋友可以通过以下方式获取。如果没兴趣,可以跳过这个步骤。

mac搭建go环境报错: go command not found

注意:以下GOPAT自己新建一个目录,不要放在go的安装目录下,会报错

sudo vi ~/.bash_profile

export GOPATH=/Users/GoWorkEnv

export GOBIN=$GOPATH/bin

export PATH=$PATH:$GOBIN

source ~/.bash_profile

go env

正常如下:

配置软连接

sudo ln -fs /usr/local/go/bin/go /usr/local/bin/go

ln -fs 强力创建符号连接(symlinks)

符号连接类似windows 的快捷方式

mac端 go语言环境配置问题

修改完环境变量,要执行一个命令应用一下

source .bash_profile


网站标题:mac下go语言环境配置,mac 安装go
本文来源:http://cdkjz.cn/article/dscjcig.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220