发布于 2014-12-27 09:05:24 | 328 次阅读 | 评论: 0 | 来源: PHPERZ

这里有新鲜出炉的GO语言教程,程序狗速度看过来!

Go语言

Go是一种新的语言,一种并发的、带垃圾回收的、快速编译的语言。Go是谷歌2009年发布的第二款编程语言。2009年7月份,谷歌曾发布了Simple语言,它是用来开发Android应用的一种BASIC语言。


本文为大家讲解的是在windows+linux下安装Go语言的方法,感兴趣的同学参考下。

Go简介

Go是一种新的语言,一种并发的、带垃圾回收的、快速编译的语言。Go是谷歌2009年发布的第二款编程语言。2009年7月份,谷歌曾发布了Simple语言,它是用来开发Android应用的一种BASIC语言。

Go官网

http://golang.org/

下载地址

http://golang.org/dl/

安装环境

32位系统 - go1.3.linux-386.tar.gz

64位系统 - go1.3.linux-amd64.tar.gz

Linux下Go安装

假定你想要安装Go的目录为 $GO_INSTALL_DIR

tar zxvf go1.0.3.linux-amd64.tar.gz -C $GO_INSTALL_DIR

vim $HOME/.profile  //或者修改/etc/profile

加入两行:

export GOROOT=$GO_INSTALL_DIR/go    // Go安装目录

export PATH=$PATH:$GOROOT/bin       // 环境变量

source $HOME/.profile

GOROOT只有在自定义安装目录时,才需要设置。

执行命令

[root@localhost] go version

>> go version go1.3 linux/amd64


[root@localhost] go

Go is a tool for managing Go source code.

Usage:

go command [arguments]

The commands are:

build       compile packages and dependencies
clean       remove object files
env         print Go environment information
fix         run go tool fix on packages
fmt         run gofmt on package sources
get         download and install packages and dependencies
install     compile and install packages and dependencies
list        list packages
run         compile and run Go program
test        test packages
tool        run specified go tool
version     print Go version
vet         run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

c           calling between Go and C
filetype    file types
gopath      GOPATH environment variable
importpath  import path syntax
packages    description of package lists
testflag    description of testing flags
testfunc    description of testing functions

Use "go help [topic]" for more information about that topic.

Windows下安装

安装环境

32位系统 - go1.3.windows-386.zip
64位系统 - go1.3.windows-amd64.zip

假定你想安装的目录为:C:\Go

环境变量

这里,我们将设置一下环境变量

右键点击计算机-> 属性-> 高级系统设置->环境变量

用户变量:针对当前用户有效。
系统变量:针对所有用户有效。

新建变量名:GOROOT。变量值:C:\Go
新建变量名:GOPATH。变量值:D:\goroot
编辑变量Path:变量值最后加入:%GOROOT%\bin

运行

开启CMD命令行窗口。

安装成功!

运行Go程序

1、创建脚本:test.go

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

2、执行脚本

go run hello.go

3、程序输出

hello, world


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务