View on GitHub

Ment.Niu

To eke out a living Live is better than burning

Centos7安装Go语言环境

CentOS7下GO环境搭建,包括安装和使用martini框架进行测试


#首先安装Centos7的升级包

#yum update 

#安装golang和vim插件

 yum install golang vim golang-vim

#设置GO代码位置

 mkdir /opt/golang
 echo "export GOPATH=$GOPATH:/opt/golang" >>~/.bash_profile
 source ~/.bash_profile

#安装 Mercurial

#go get 需要安装Mercurial版本管理系统或Git管理,安装hg和git

 yum install mercurial git

#此处以构建go-martini项目作为示例构建go项目
#获得go-martini代码

go get github.com/go-martini/martini

#进入目录/opt/golang/src 创建并编辑文本server.go


package main

import "github.com/go-martini/martini"

func main() {
  m := martini.Classic()
  m.Get("/", func() string {
    return "Hello world!"
  })
  m.Run()
}

#关闭firewalld,测试程序运行情况

chkconfig firewalld off
service firewalld stop
go run server.go

#访问IP:3000查看运行情况

helloword