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


    本文包括:1)安装Go语言。2)运行第一个Go语言。3)增加vim中对Go语言的高亮支持。

    1、安装Go语言

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

      1.1、修改环境变量

      编辑文件~/.bashrc

    vim ~/.bashre

      在文件最后添加如下代码

    # about go language
    export GOROOT=$HOME/go
    export GOARCH=386
    export GOOS=linux
    export GOBIN=$HOME/bin 

      1.4、解压

    tar xzf go1.3.3.linux-386.tar.gz
    
    $ls
    go
    go1.3.3.linux-386.tar.gz

      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、程序代码如下

    package main                                                                                                  
    
    import (
            "fmt"
            "runtime"
           )   
    
    func main() {
        fmt.Println("Hellow World!", runtime.Version())
    }

      2.2、运行

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

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

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

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

    $ cd ~/go/misc/vim/
    $ ls
    autoload  compiler  ftdetect  ftplugin  indent  plugin  readme.txt  syntax

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

    $ 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/misc/vim/中有对应的 syntax, ftplugin, indent, compiler 中的go.vim文件复制到/usr/share/vim/vim74/对应目录,ftdetect文件夹包括文件复制到vim73中。

    作者:风波

    mail : fengbohello@qq.com

  • 相关阅读:
    【PAT Advanced Level】1008. Elevator (20)
    模块的耦合和内聚
    《深入理解计算机系统》--链接
    HDU 1077Catching Fish(简单计算几何)
    [置顶] VC++界面编程之--自定义CEdit(编辑框)皮肤
    使用VS2012 开发SharePoint 2013 声明式的action(activity) 综合实例
    java 创建线程的三种方法Callable,Runnable,Thread比较及用法
    代码审计技巧讲解
    IP地址后面斜杠加具体数字详解
    80端口被system进程占用解决方法
  • 原文地址:https://www.cnblogs.com/fengbohello/p/4319643.html
Copyright © 2020-2023  润新知