Ubuntu下安装go语言(转自豆瓣的网友)

来源:互联网 发布:单片机仿真常用代码 编辑:程序博客网 时间:2024/05/24 07:15
ubuntu 下安装go


1 安装C语言工具集(可选)


sudo apt-get install bison ed gawk gcc libc6-dev make


2 安装SCM 源代码控制管理工具Mercurial(可选)
   go源码使用Mercurial管理
  
    2.1 安装mercurial依赖
    sudo apt-get install python-setuptools python-dev build-essential
  
    2.2 安装mercurial
    sudo easy_install mercurial
  
3 获取go的源代码
itang@itang-laptop:~/sources$ hg clone -r release https://go.googlecode.com/hg/ go


4 安装go


    4.1 编译安装
    itang@itang-laptop:~/sources$ cd go/src
    itang@itang-laptop:~/sources/go/src$ ./all.bash
    ...
    --- cd ../test
    1 known bugs; 0 unexpected bugs


    ---
    Installed Go for linux/386 in /home/itang/sources/go.
    Installed commands in /home/itang/sources/go/bin.
    *** You need to add /home/itang/sources/go/bin to your $PATH. ***
    The compiler is 8g.


    4.2 配置环境变量
    itang@itang-laptop:~/sources/go/src$ gedit  ~/.profile
    在文件最后加上一下两行:
    export GO_HOME=/home/itang/sources/go
    export PATH=$GO_HOME/bin:$PATH


    itang@itang-laptop:~/sources/go/src$ source ~/.profile


5 hello,world


    5.1 coding
    itang@itang-laptop:~/sources/go/src$ cd ~/test
    itang@itang-laptop:~/test$ gedit hello.go
    输入:
    package main
    import "fmt"
    func main() {
            fmt.Printf("hello, 世界\n")
    }


    5.2 编译/链接/运行
    itang@itang-laptop:~/test$ 8g hello.go
    itang@itang-laptop:~/test$ 8l hello.8
    itang@itang-laptop:~/test$ ./8.out
    hello, 世界




6 跟上go的最新发布
   $ cd go/src
   $ hg pull
   $ hg update release
   $ ./all.bash


大功告成! 可以进入下一步的go 语言学习了。


(注:国人翻译了go的文档,见http://code.google.com/p/golang-china/)
还有....注意是转载的 原帖在这里(http://www.douban.com/note/101367682/?start=0&post=ok#last)
原创粉丝点击