ubuntu go 开发环境搭建
下载 go1.12.4.linux-amd64.tar.gz
wget https://dl.google.com/go/go1.12.4.linux-amd64.tar.gz
sudo tar -zxvf go1.12.4.linux-amd64.tar.gz -C /opt
检查安装是否成功
cd /opt/go/bin
./go version
go version go1.12.4 linux/amd64
设置环境变量
vi /etc/profile
export GOROOT=/opt/go
export GOPATH=/home/ubuntu/go
export GOPROXY=https://goproxy.io
export GOARCH=amd64
export GOOS=linux
export GOTOOLS=$GOROOT/pkg/tool
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source /etc/profile
其中,GOPROXY 可以解决 golang.org/x/... 系列包无法下载的问题。
编写 HelloWorld 文件,测试运行环境。
package main
import "fmt"
func main(){
fmt.Println("hello,world!")
}
go run hello.go
go build hello.go
创建 go.mod 文件
go mod init hello
用 Gin 实现一个简单的 http 服务
import (
"gopkg.in/gin-gonic/gin.v1"
"net/http"
)
func main(){
router := gin.Default()
router.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Hello World")
})
router.Run(":8000")
}
直接编译执行
go run hello
可以看到引用的包都被自动下载了
go: finding github.com/gin-contrib/sse latest
go: finding github.com/gin-gonic/gin/render latest
go: finding github.com/gin-gonic/gin/binding latest
go: finding github.com/gin-gonic/gin/json latest
go: finding golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
go: downloading golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
go: finding gopkg.in/go-playground/validator.v8 v8.18.2
go: finding github.com/ugorji/go/codec latest
go: finding github.com/golang/protobuf/proto latest
go: finding gopkg.in/yaml.v2 v2.2.2
go: downloading gopkg.in/go-playground/validator.v8 v8.18.2
go: downloading gopkg.in/yaml.v2 v2.2.2
go: finding github.com/ugorji/go v1.1.4
go: finding github.com/golang/protobuf v1.3.1
go: downloading github.com/ugorji/go v1.1.4
go: downloading github.com/golang/protobuf v1.3.1
go: extracting gopkg.in/go-playground/validator.v8 v8.18.2
go: extracting gopkg.in/yaml.v2 v2.2.2
go: extracting github.com/golang/protobuf v1.3.1
go: extracting github.com/ugorji/go v1.1.4
go: extracting golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
go: finding gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
HTTP 服务启动正常,可以通过浏览器访问了。
[GIN-debug] [WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET / --> main.main.func1 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8000
ubuntu go 开发环境搭建的更多相关文章
- ubuntu java开发环境搭建(jdk+tomcat+eclipse)
一.jdk的安装配置. 1.下载jdk. 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-213 ...
- 【Ubuntu Java 开发环境搭建 】
配置环境变量 在终端下: sudo gedit /etc/profile 这里当然有些熟悉ubuntu的朋友也可以用 vim, 刚从windows转过来的朋友还是用gedit看着舒服写. ...
- Windows7+VirtualBox+Ubuntu本地开发环境搭建
首先下载相应的VirtualBox和Ubuntu镜像文件 安装Ubuntu操作系统 一 网络设置 将虚拟机的network连接模式设置为Bridge模式,注意无线网卡要与本机的无线网卡名称一致 在wi ...
- ubuntu scrapy 开发环境搭建
我的版本是14.04 1.更新系统 ##如果系统没有换国内下载路径需要换下系统的更新下载路径 http://www.cnblogs.com/seablog/p/7043798.html sudo a ...
- Ubuntu下开发环境搭建
安装基础开发包,主要gcc,g++等 sudo apt-get install build-essential 未完待续
- 我的开发环境搭建(ubuntu菜鸟)
前段时间把系统换成了ubuntu,经过一段时间到发展,终于可以比较正常到完成开发工作了,但是就在今天,我的系统崩了,进不了桌面,而且终端里边到中文也显示乱码,尝试了网上说到各种方法无效,最终我决定重装 ...
- odoo开发环境搭建(二):安装Ubuntu 17虚拟机
odoo开发环境搭建(二):安装Ubuntu 17虚拟机 下载镜像文件: 配置网络: 安装vmware tools: 配置共享文件夹: 选中虚拟机,右键编辑设置里边配置共享文件夹,指定windows本 ...
- win10子系统linux.ubuntu开发环境搭建
移步新博客... win10子系统linux.ubuntu开发环境搭建
- OK335xS Ubuntu 12.04.1 版本 Android 开发环境搭建
/******************************************************************************************** * OK33 ...
随机推荐
- KMP算法详解&&P3375 【模板】KMP字符串匹配题解
KMP算法详解: KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt(雾)提出的. 对于字符串匹配问题(such as 问你在abababb中有多少个 ...
- 《Python基础教程》第四章:字典
字典中的值没有特殊的顺序 电话号码(以及其他可能以0开头的数字)应该表示为数字字符串,而不是整数 dict函数可以通过序列对建立字典 clear方法清除字典中所有的项.这是个原地操作,无返回值 get ...
- oracle—数据泵及常用参数
-- 1.创建目录dumpcreate or replace directory dump as '/home/oracle/dump'; -- 2.授权:Grant read,write on di ...
- Java-UploadHelper工具类
/** * 上传文件类 */ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java. ...
- @Value和@ConfigurationProperties
1.@Value用法 https://blog.csdn.net/u010832551/article/details/73826914 2.@ConfigurationProperties用法 ht ...
- python中的list,tuple,dict,set简介---陈雨童
变量和对象 变量把对象和自己连接起来(指针连接对象空间),引用建立了变量和对象之间的映射关系,这就是引用.引用完成,就实现了赋值.变量通过对象的内存地址指向对象,类似于软链接 将变量a赋值给变量b,其 ...
- Java 添加、删除、移动、隐藏/显示Excel工作表
本文内容将介绍通过Java程序如何添加.删除.移动工作表,以及设置工作表隐藏.显示等操作.文中使用了Java Excel类库(Free Spire.XLS for Java 免费版),可通过官网下载包 ...
- 4、路由事件 RoutedEvent
路由事件的类型:具体参考https://www.cnblogs.com/jellochen/p/3475754.html Tunnel隧道方式:路由事件使用隧道策略,以便事件实例通过树向下路由(从根到 ...
- springboot错误1 Failed to execute goal org.springframework.boot:spring-boot-maven-plugin
关于Springboot打包错误的问题 | Failed to execute goal org.springframework.boot:spring-boot-maven-plugin https ...
- CUDA-F-2-1-CUDA编程模型概述2
Abstract: 本文继续上文介绍CUDA编程模型关于核函数以及错误处理部分 Keywords: CUDA核函数,CUDA错误处理 开篇废话 今天的废话就是人的性格一旦形成,那么就会成为最大的指向标 ...