go语言之hello world

看到一篇新闻,莫名的想试一试被某些人推崇备至的go语言……

1. 开发环境搭建

【当然可以直接安装已经编译好的二进制包,而且Ubuntu的傻瓜式安装很给力,这里给出的是Ubuntu中的编译步骤】

(1)安装 mercurial工具,为了获得hg命令;

(2)设置环境变量GOROOT

export GOROOT=~/Go

这里当然需要你新建一个Go目录用来作为存放源码的目录……微笑

(3)获取go的源代码

hg clone -r release https://go.googlecode.com/hg/ $GOROOT

网速不好,竟然花了几分钟才把代码搞下来……睡觉

(4)这下终于可以编译源码了……

cd $GOROOT/src

./all.bash

虚拟机里面的Ubuntu编译起来慢得要死……睡觉,慢慢等吧……

编译完成后可以看到输出:

ALL TESTS PASSED

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

(5)需要继续设置环境变量

export PATH=$GOROOT/bin:$PATH

2. 开始写hello world

(1)编写源码

package main
import "fmt"
func main(){
    fmt.Printf("Hello Go!\n")
}
(2)编译源码

go build helloworld.go

(3)执行,可以看到结果

./helloworld

可以看到输出:Hello Go!

3. go语言

【直接copy过来,英文太差就不翻译了】

 Go aims to provide the efficiency of astatically typed compiled language with the ease of programming of a dynamiclanguage.[9] Other goals include:

   Safety: Type-safe and memory-safe.

   Good support for concurrency and communication.

   Efficient, latency-free garbage collection.

   High-speed compilation.

特性很多,以后有空再玩……微笑






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值