Ubuntu 安装最新版 (1.12) Golang 并使用 go mod
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 安装最新版 (1.12) Golang 并使用 go mod的更多相关文章
- Ubuntu 安装最新版nodejs
转自:ubuntu快速安装最新版nodejs,只需2步 第一步,去 nodejs 官网 https://nodejs.org 看最新的版本号: 也就是说此时此刻,12.6.0 是最新的版本,不过你求稳 ...
- Ubuntu安装最新版的nodejs
安装玩Ubuntu的虚拟机之后安装nodejs发现npm的版本才3.5.2,这都多老了?于是Google了一下,发现是由于Ubuntu官方维护的包源太老了,想要安装nodejs的最新版,两种方法,一种 ...
- Ubuntu安装最新版nodejs
今天在学习以太坊时,需要用到nodejs,因为使用的是ubuntu 16.04 LTS,一直安装的是老版本的nodejs,官方给方法用不成,折腾了半天,什么软链.手动编译,总觉得不很靠谱(linux水 ...
- ubuntu -- 安装最新版的nodejs
1.安装最新的nodejs和npm # apt-get update # apt-get install -y python-software-properties software-properti ...
- ubuntu安装最新版node和npm
1.先在系统上安装好nodejs和npm sudo apt-get install nodejs-legacy sudo apt-get install npm 2.升级n ...
- [190308]Ubuntu 安装完之后,安装的软件小记
install software vim sudo apt-get install -y vim Typora command copy from Typora website # or run: # ...
- Ubuntu 14.04中安装最新版Eclipse
Ubuntu 14.04中安装最新版Eclipse 来源:Linux社区 作者:Linux 1.安装OpenJDK Java 7 如果你的系统中没有安装Java,我们需要按照如下步骤事先安装好 ...
- Ubuntu安装Navicat 12 for MySQL
环境准备 要想运行Navicat,必须先安装Wine,这个可以使用下面的命令来安装Wine: ubuntu@ubuntu ~ $ sudo apt-get install wine-stable 安装 ...
- Win10系统XWware虚拟机安装Linux系统(Ubuntu)最新版教程
XWware虚拟机安装Linux系统(Ubuntu)教程 一.下载并安装VMware虚拟机 借助VMware Workstation Pro, 我们可以在同一台Windows或Linux PC上同时运 ...
随机推荐
- 解决selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in P
转载 解决selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be i ...
- python-gitlab 之更改 merge_method
参考: https://docs.gitlab.com/ee/api/projects.html https://python-gitlab.readthedocs.io/en/stable/gl_o ...
- 接口自动化--unittest
今天我介绍一个测试框架:不管我们是做接口自动化还是UI自动化,我们都要用的一个框架---unittest unittest是python里面的一个单元测试框架,我们做自动化测试的话,都是要用到这个测试 ...
- Broadcast,Scatter,Gather,Reduce,All-reduce分别是什么?
Broadcast 看名字就很好理解了,其实就是把同一份数据分发广播给所有人,示意图如下: Scatter 不同于Broadcast, scatter可以将不同数据分发给不同的进程. Gather 这 ...
- 编程题:SaturdayNightStay
"输入2019年的一个时间段,开始时间代表出发,结束时间代表在那一天返回,判断在该时间段内,如果旅行有多少个子时间段可以在周六晚上休息" * 周六晚上休息,即子时间段必须包含周六, ...
- HDU6701:Make Rounddog Happy(启发式分治)
题意:给定数组a[],求区间个数,满足区间的数各不同,而且满足maxval-len<=K: 思路:一看就可以分治做,对于当前的区间,从max位置分治. 对于这一层,需要高效的统计答案,那么对短的 ...
- HDU6592 Beauty Of Unimodal Sequence
Beauty Of Unimodal Sequence 给一个序列,在满足单调递增或者单调递减或者先增后减的最长子序列集合里找到下标字典序最大以及最小的两个子序列,输出这两个子序列里元素的下标. n≤ ...
- hihocoder#1046: K个串
[传送门] 这种区间内相同数字只能被统计一次/只有区间内数字都不相同才对答案有贡献的题都可以用扫描线扫右端点,表示当前区间右端点为$r$.然后当前线段树/树状数组维护区间左端点为$[1,r)$时对应的 ...
- jQuery中判断数组
判断数组里面是否包含某个元素可以使用 $.inArray("元素(字符串)",数组名称) 进行判断 ,当存在该元素(字符串)时,返回该元素在数组的下标,不存在时返回 -1 jQ=& ...
- Implementing the Singleton Pattern in C#
Table of contents (for linking purposes...) Introduction Non-thread-safe version Simple thread safet ...