Golang入门-----安装配置篇
2017-06-07 19:19
330 查看
Go语言是一种开源的编程语言,它旨在使我们能够方便地构建简单、 可靠、 高效的软件。
安装
下载地址:1.1. https://golang.org/dl/
1.2. https://dl.gocn.io
编译安装(Linux环境)
# go1.4.3版本依赖于GCC环境 $ cd ~ $ mkdir {local,go} $ tar -zxvf go1.4.3.src.tar.gz -C /home/go/local/ $ cd local $ mv go/ go1.4.3/ $ cd go1.4.3/src $ ./make.bash $ tar -zxvf go1.8.linux-amd64.tar.gz -C /home/go/local/ $ cd ~/local/go/ $ export GOROOT_BOOTSTRAP=/home/go/local/go1.4.3/ $ ./make.bash #配置环境变量 $ ~/.bashrc export GOROOT=$HOME/local/go export GOPATH=$HOME/go export PATH=$GOROOT/bin:$GOPATH/bin:$PATH $ source ~/.bashrc #验证安装是否成功 $go version #版本 go version go1.8 linux/amd64 $go env #环境变量 GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/go/go" GORACE="" GOROOT="/home/go/local/go" GOTOOLDIR="/home/go/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build156894198=/tmp/go-build" CXX="g++" CGO_ENABLED="1" PKG_CONFIG="pkg-config" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2"
基本使用
1.基本语法$ go --help 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 doc show documentation for package or symbol env print Go environment information bug start a bug report fix run go tool fix on packages fmt run gofmt on package sources generate generate Go files by processing source 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 buildmode description of build modes filetype file types gopath GOPATH environment variable environment environment variables 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.
2.测试案例
$ cd ~/go $ vi hello.go package main import "fmt" func main() { fmt.Println("Hello,golang") } $ go run hello.go hello world
3.跨平台编译
go可以实现一个平台开发,编译为多个平台版本。同平台随意拷贝执行。
#windows平台,可以放在windows环境执行 $GOOS=windows go build -o hello.windows.exe helloworld.go #Mac平台,可以放在Mac环境执行 $GOOS=darwin go build -o hello.mac helloworld.go #Linux平台 $GOOS=linux go build -o hello.linux helloworld.go
4.格式化代码
#方法1:gofmt格式化 $gofmt -w hello.go #方法2:goimports格式化代码,但是 goimports 不是自带的,需要额外安装,而且可以补齐缺少的import对象。 安装goimports: $ mkdir -p $GOPATH/src/golang.org/x $ cd $GOPATH/src/golang.org/x $ git clone https://github.com/golang/tools.git $ go install golang.org/x/tools/cmd/goimports $ goimports -w hello.go
IDE工具选择
1、Atom配合go-plus插件。2、LitelDE,专用IDE。
3、emacs + spacemacs配置
4、Eclipse等。
具体使用啥,熟悉哪个用哪个
相关文章推荐
- GoLang入门1-安装-配置
- Android 入门—— 安装和配置
- MySQL基础入门-03MySQL的安装和配置
- 开源工作流引擎Shark入门1——安装与配置
- CAS入门学习— 安装与配置
- DNN入门笔记二:安装及配置
- LINUX新手入门及安装配置faq200(上)
- Red5安装与入门 与FMS配置
- 《Visual C++ 2010入门教程》系列二:安装、配置和首次使用VS2010(转)
- 安装配置:ZIP版本的Tomcat配置新手入门
- LINUX新手入门及安装配置faq200(下)
- AJAX入门一-AJAX安装与ASP.NET AJAX Documentation的安装配置
- ASP入门与实例---IIS的安装与配置
- Android入门一:Android 开发环境安装配置手册
- eVC4.0进行smartphone或packet PC开发新手入门(开发工具下载,安装,配置)
- LINUX新手入门及安装配置faq200(上)
- Python入门[0]之安装和配置Python
- Linux下mysql安装配置入门知识
- HBase入门笔记(三)-- 完全分布模式Hadoop集群安装配置
- JBoss Portal入门2:安装与配置