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 ...
随机推荐
- 【SDR】UHD安装教程
USRP作为软件无线电系统中常用的射频设备,其驱动UHD的安装及稳定运行,是SDR系统稳定的必备条件,该篇博客总结UHD的相关安装方法,主要有三种,分别是apt-get.github clone源码编 ...
- 201871010104-陈园园《面向对象程序设计(java)》第十七周学习总结
201871010104-陈园园<面向对象程序设计(java)>第十七周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ ...
- CF888G Xor-MST[最小生成树+01trie]
前注:关于这题,本人的解法暂时没有成功通过此题,原因是被卡常了.可能需要等待某种机缘来请人调试. 类似uoj的一道题(新年的繁荣),不过是一个有些简单的版本. 因为是完全图,有没有办法明显优化建边,所 ...
- Myeclipse中左边的项目目录没了
切换一下Perspective, java, resource都有项目窗口 具体的 Window->Open Perspective 如果项目窗口被关了的话 windows->show v ...
- printf格式输出
参考:http://www.cplusplus.com/reference/cstdio/printf/ C string that contains the text to be written t ...
- python3爬虫--shell命令的使用和firefox firebug获取目标信息的xpath
scrapy version -v #该命令用于查看scrapy安装的相关组件和版本 一个工程下可创建多个爬虫 scrapy genspider rxmetal rxmetal.com scrapy ...
- Postman之 SSL证书配置随手记
参考文档: https://learning.getpostman.com/docs/postman/sending_api_requests/certificates/ 随着 https 的推动,更 ...
- Python之hmac模块的使用
hmac模块的作用: 用于验证信息的完整性. 1.hmac消息签名(默认使用MD5加算法) #!/usr/bin/env python # -*- coding: utf-8 -*- import h ...
- xml配置文件 操作
public class ConfigFile { protected readonly string configBasePath = "Root/Config"; /// &l ...
- react-native-swiper的Github地址
https://github.com/liyinglihuannan/react-native-swiper https://www.jianshu.com/p/4dba338ef37a(中文版