且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

初识GO语言——安装Go语言

更新时间:2022-09-21 19:02:16

1、安装Go语言

  本文采用源码安装Go语言,Go语言的源代码在百度网盘 http://pan.baidu.com/s/1mguZqhM

  1.1、修改环境变量

  编辑文件~/.bashrc

vim ~/.bashre

  在文件最后添加如下代码

初识GO语言——安装Go语言
# about go language
export GOROOT=$HOME/go
export GOARCH=386
export GOOS=linux
export GOBIN=$HOME/bin 
初识GO语言——安装Go语言

  1.4、解压

初识GO语言——安装Go语言
tar xzf go1.3.3.linux-386.tar.gz

$ls
go
go1.3.3.linux-386.tar.gz
初识GO语言——安装Go语言

  1.5、把go目录移动到家目录下

mv go ~/

  1.6、编译

cd ~/go/src
./all.bash

在执行“Checking API compatibility”的时候可能会卡一会儿……

1.7、编译完成后开始测试编译结果,执行下面代码

$ go version
go version go1.3.3 linux/386

可以看到,我们的Go语言版本是1.3.3

2、下面开始我们的第一个Go语言程序

  2.1、程序代码如下

初识GO语言——安装Go语言
package main                                                                                                  

import (
        "fmt"
        "runtime"
       )   

func main() {
    fmt.Println("Hellow World!", runtime.Version())
}
初识GO语言——安装Go语言

  2.2、运行

$ go run aa.go 
Hellow World! go1.3.3

3、到目前,我们的Go语言算是可以运行了,呵~呵~。接下来增加vim中对Go语言的高亮支持

  3.1、增加vim中对Go语言的高亮支持

  进入我们的go源代码目录,ls查看,会发现如下几个目录和文件

初识GO语言——安装Go语言
$ cd ~/go/misc/vim/
$ ls
autoload  compiler  ftdetect  ftplugin  indent  plugin  readme.txt  syntax
初识GO语言——安装Go语言

  查看系统中对vim配置的目录

初识GO语言——安装Go语言
$ ls /usr/share/vim/vim73/
autoload       delmenu.vim   ftoff.vim     gvimrc_example.vim  lang        plugin       synmenu.vim
bugreport.vim  doc           ftplugin      indent              macros      print        syntax
colors         evim.vim      ftplugin.vim  indent.vim          menu.vim    rgb.txt      tutor
compiler       filetype.vim  ftplugof.vim  indoff.vim          mswin.vim   scripts.vim  vimrc_example.vim
debian.vim     ftdetect      go            keymap              optwin.vim  spell
初识GO语言——安装Go语言

我们会发先,其中有和go目录下相对应的目录或文件,将下载目录的 go/misc/vim/中有对应的 syntax, ftplugin, indent, compiler 中的go.vim文件复制到/usr/share/vim/vim74/对应目录,ftdetect文件夹包括文件复制到vim73中。


本文转自郝峰波博客园博客,原文链接:http://www.cnblogs.com/fengbohello/p/4319643.html,如需转载请自行联系原作者