Go 语言学习笔记 1 (安装开发环境)

at28997146 · · 1652 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

    本文只针对Ubuntu系统开发环境的搭建进行学习。

    本文工作操作系统为ubuntu12.12.

第一步,安装Go工具链:

root@tangle-VirtualBox:/home/tangle# sudo apt-get install bison ed gawk gcc libc6-dev make
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ed is already the newest version.
gcc is already the newest version.
libc6-dev is already the newest version.
make is already the newest version.
The following extra packages will be installed:
  libbison-dev libsigsegv2
Suggested packages:
  bison-doc
The following NEW packages will be installed:
  bison gawk libbison-dev libsigsegv2
0 upgraded, 4 newly installed, 0 to remove and 160 not upgraded.
Need to get 760 kB of archives.
After this operation, 2,998 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://cn.archive.ubuntu.com/ubuntu/ precise/main libsigsegv2 i386 2.9-4ubuntu2 [14.4 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu/ precise/main gawk i386 1:3.1.8+dfsg-0.1ubuntu1 [438 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu/ precise/main libbison-dev i386 1:2.5.dfsg-2.1 [33.2 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu/ precise/main bison i386 1:2.5.dfsg-2.1 [275 kB]
Fetched 760 kB in 1s (411 kB/s)
Selecting previously unselected package libsigsegv2.
(Reading database ... 154983 files and directories currently installed.)
Unpacking libsigsegv2 (from .../libsigsegv2_2.9-4ubuntu2_i386.deb) ...
Setting up libsigsegv2 (2.9-4ubuntu2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Selecting previously unselected package gawk.
(Reading database ... 154991 files and directories currently installed.)
Unpacking gawk (from .../gawk_1%3a3.1.8+dfsg-0.1ubuntu1_i386.deb) ...
Selecting previously unselected package libbison-dev.
Unpacking libbison-dev (from .../libbison-dev_1%3a2.5.dfsg-2.1_i386.deb) ...
Selecting previously unselected package bison.
Unpacking bison (from .../bison_1%3a2.5.dfsg-2.1_i386.deb) ...
Processing triggers for man-db ...
Setting up gawk (1:3.1.8+dfsg-0.1ubuntu1) ...
Setting up libbison-dev (1:2.5.dfsg-2.1) ...
Setting up bison (1:2.5.dfsg-2.1) ...
update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode.
root@tangle-VirtualBox:/home/tangle# 


 

第二步 安装Mercurial版本管理系统

root@tangle-VirtualBox:/home/tangle# apt-get install mercurial
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  mercurial-common
Suggested packages:
  qct wish kdiff3 tkdiff meld xxdiff python-mysqldb python-pygments
The following NEW packages will be installed:
  mercurial mercurial-common
0 upgraded, 2 newly installed, 0 to remove and 23 not upgraded.
Need to get 1,982 kB of archives.
After this operation, 6,691 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://cn.archive.ubuntu.com/ubuntu/ precise/universe mercurial-common all 2.0.2-1ubuntu1 [1,945 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu/ precise/universe mercurial i386 2.0.2-1ubuntu1 [37.1 kB]
Fetched 1,982 kB in 4s (490 kB/s)
Selecting previously unselected package mercurial-common.
(Reading database ... 155146 files and directories currently installed.)
Unpacking mercurial-common (from .../mercurial-common_2.0.2-1ubuntu1_all.deb) ...
Selecting previously unselected package mercurial.
Unpacking mercurial (from .../mercurial_2.0.2-1ubuntu1_i386.deb) ...
Processing triggers for man-db ...
Setting up mercurial-common (2.0.2-1ubuntu1) ...
Setting up mercurial (2.0.2-1ubuntu1) ...

Creating config file /etc/mercurial/hgrc.d/hgext.rc with new version
root@tangle-VirtualBox:/home/tangle# 


 

第三步 获取go语言源代码

root@tangle-VirtualBox:/home/tangle# hg clone -r release https://go.googlecode.com/hg/ go
adding changesets
adding manifests
adding file changes
added 16303 changesets with 58951 changes to 8102 files
updating to branch release-branch.go1.1
3747 files updated, 0 files merged, 0 files removed, 0 files unresolved
root@tangle-VirtualBox:/home/tangle# 


第四部 编译并安装go

root@tangle-VirtualBox:/home/tangle# cd go/src/
root@tangle-VirtualBox:/home/tangle/go/src# ./all.bash 
# Building C bootstrap tool.
cmd/dist

 

中间编译过程在此略过,如果安装成功最后会出现如下信息

# Checking API compatibility.
Go version is "go1.1.1", ignoring -next /home/tangle/go/api/next.txt
~pkg net, func ListenUnixgram(string, *UnixAddr) (*UDPConn, error)
~pkg syscall (darwin-386), func Fchflags(string, int) error
~pkg syscall (darwin-386-cgo), func Fchflags(string, int) error
~pkg syscall (darwin-amd64), func Fchflags(string, int) error
~pkg syscall (darwin-amd64-cgo), func Fchflags(string, int) error
~pkg syscall (freebsd-386), func Fchflags(string, int) error
~pkg syscall (freebsd-amd64), func Fchflags(string, int) error
~pkg text/template/parse, type DotNode bool
~pkg text/template/parse, type Node interface { Copy, String, Type }

ALL TESTS PASSED

---
Installed Go for linux/386 in /home/tangle/go
Installed commands in /home/tangle/go/bin
*** You need to add /home/tangle/go/bin to your PATH.

 

    按照安装完成后的提示信息将/home/tangle/go/bin 添加到PATH环境变量中

root@tangle-VirtualBox:/home/tangle/go/src# export PATH=$PATH:/home/tangle/go/bin
root@tangle-VirtualBox:/home/tangle/go/src# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/tangle/go/bin

 

最后, 编写hello world 验证开发环境

root@tangle-VirtualBox:/home/tangle/go/go-test# cat hello.go 
package main
import "fmt"
func main() {
        fmt.Printf("hello, world\n")
}
root@tangle-VirtualBox:/home/tangle/go/go-test# 
root@tangle-VirtualBox:/home/tangle/go/go-test# go build hello.go 
root@tangle-VirtualBox:/home/tangle/go/go-test# ls
hello  hello.go
root@tangle-VirtualBox:/home/tangle/go/go-test# ./hello 
hello, world






 


有疑问加站长微信联系(非本文作者)

本文来自:CSDN博客

感谢作者:at28997146

查看原文:Go 语言学习笔记 1 (安装开发环境)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1652 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传