新聞中心
ubuntu下怎么配置go語言開發(fā)環(huán)境
具體步驟:
在葉城等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、做網(wǎng)站、外貿(mào)營銷網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站制作,葉城網(wǎng)站建設(shè)費用合理。
1、去官網(wǎng)下載go1.1.2的tarball,一般下載到tem目錄
2、打開終端cd /usr/local, tar -zxvf go1.1.2.linux-386.tar.gz
將源碼文件解壓縮到/usr/local目錄,如果解壓到其他目錄,需要自己設(shè)置GOROOT
3、安裝gcc工具,因為golang有些功能是使用c寫
sudo apt-get install bison gawk gcc libc6-dev make
4、$ cd go/src,$ ./all.bash
運行bash腳本,如果運行正常會獲得你的操作系統(tǒng)和cpu信息,自動編譯安裝
5、將export PATH=$PATH:/usr/local/go/bin 寫入$HOME/.profile
最后進行測試輸入go version 會顯示go1.1.2 linux/386
windows 怎么編譯 go語言
1、解壓壓縮包到go工作目錄,如解壓到E:\opensource\go\go,解壓后的目錄結(jié)構(gòu)如下:
E:\opensource\go\go
├─api
├─bin
│ ├─go.exe
│ ├─godoc.exe
│ └─gofmt.exe
├─doc
├─include
├─lib
├─misc
├─pkg
├─src
└─test
2、增加環(huán)境變量GOROOT,取值為上面的go工作目錄
3、Path環(huán)境變量中添加";%GOROOT%\bin",以便能夠直接調(diào)用go命令來編譯go代碼,至此go編譯環(huán)境就配置好了
注:如果不想手動設(shè)置系統(tǒng)環(huán)境變量,也可下載go啟動環(huán)境批處理附件,
修改goenv.bat文件中的GOROOT值為上面的go工作目錄后直接雙擊該bat文件,go編譯環(huán)境變量即設(shè)置完成。
4、測試go編譯環(huán)境,啟動一個cmd窗口,直接輸入go,看到下面的提示就是搭建成功了
E:\opensource\go\gogo
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 run godoc on package sources
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:
gopath GOPATH environment variable
packages description of package lists
remote remote import path syntax
testflag description of testing flags
testfunc description of testing functions
Use "go help [topic]" for more information about that topic.
5、編譯helloworld測試程序,go語言包中test目錄帶有helloworld.go測試程序,源碼見"附一 helloworld.go",
直接調(diào)用"go build helloworld.go"就生成了"helloworld.exe"可執(zhí)行程序,運行一下這個程序看到了我們期望的hello,wolrd。
E:\opensource\go\go\testgo build helloworld.go
E:\opensource\go\go\testhelloworld.exe
hello, world
E:\opensource\go\go\test
附一 helloworld.go
// cmpout
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test that we can do page 1 of the C book.
package main
func main() {
print("hello, world\n")
}
GO語言如何編譯發(fā)布到Linux
在命令行執(zhí)行如下指令
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build main.go? //開始編譯程序
名稱欄目:termux編譯go語言的簡單介紹
URL地址:http://fisionsoft.com.cn/article/dojjohi.html