惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
Know Your Adversary
Know Your Adversary
Security Archives - TechRepublic
Security Archives - TechRepublic
Security Latest
Security Latest
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
AI
AI
O
OpenAI News
M
MIT News - Artificial intelligence
Scott Helme
Scott Helme
U
Unit 42
P
Proofpoint News Feed
罗磊的独立博客
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
Apple Machine Learning Research
Apple Machine Learning Research
T
The Exploit Database - CXSecurity.com
I
InfoQ
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
Webroot Blog
Webroot Blog
P
Palo Alto Networks Blog
C
Cybersecurity and Infrastructure Security Agency CISA
N
News and Events Feed by Topic
Cisco Talos Blog
Cisco Talos Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
A
About on SuperTechFans
美团技术团队
J
Java Code Geeks
T
Tenable Blog
L
LINUX DO - 最新话题
NISL@THU
NISL@THU
G
Google Developers Blog
Forbes - Security
Forbes - Security
爱范儿
爱范儿
S
Security @ Cisco Blogs
Project Zero
Project Zero
有赞技术团队
有赞技术团队

博客园 - 茁壮的小草

join查询中索引建议 tomcat连接池的“bug” 连接池介绍 JDBC介绍 Hadoop完全分布式搭建 Apache Hadoop YARN 使用 kubebuilder 创建并部署 k8s-operator 单链表反转 单链表操作 如何在Kubernetes 里添加自定义的 API 对象(一) 【源码】Redis命令处理过程 K8S配置存活、就绪和启动探测器 【源码】Redis exists命令bug分析 【源码】Redis Server启动过程 K8S中的Objects MAC 安装MySQL-python 公司里使用gitlab管理项目 vscode配置django开发环境最佳实战(mac) virtualenv最佳实战(windows)
搭建golang开发环境(1.14之后版本)
茁壮的小草 · 2022-02-12 · via 博客园 - 茁壮的小草

Go语言1.14版本之后推荐使用go modules管理依赖,也不再需要把代码写在GOPATH目录下。

下载地址

Go官网下载地址:https://golang.org/dl/
Go官方镜像站(推荐):https://golang.google.cn/dl/

版本的选择

Windows平台和Mac平台推荐下载可执行文件版,Linux平台下载压缩文件版。

GOROOT和GOPATH

GOROOT和GOPATH都是环境变量,其中GOROOT是我们安装go开发包的路径,而从Go 1.8版本开始,Go开发包在安装完成后会为GOPATH设置一个默认目录,并且在Go1.14及之后的版本中启用了Go Module模式之后,不一定非要将代码写到GOPATH目录下,所以也就不需要我们再自己配置GOPATH了,使用默认的即可。

GOPROXY 非常重要

Go1.14版本之后,都推荐使用go mod模式来管理依赖环境了,也不再强制我们把代码必须写在GOPATH下面的src目录了,你可以在你电脑的任意位置编写go代码。(网上有些教程适用于1.11版本之前。)

默认GoPROXY配置是:GOPROXY=https://proxy.golang.org,direct,由于国内访问不到https://proxy.golang.org,所以我们需要换一个PROXY,这里推荐使用https://goproxy.io或https://goproxy.cn。

可以执行下面的命令修改GOPROXY:

go env -w GOPROXY=https://goproxy.cn,direct

第一个Go程序

现在我们来创建第一个Go项目——hello。在我们桌面创建一个hello目录。

使用go module模式新建项目时,我们需要通过go mod init 项目名命令对项目进行初始化,该命令会在项目根目录下生成go.mod文件。例如,我们使用hello作为我们第一个Go项目的名称,执行如下命令。

编写代码

接下来在该目录中创建一个main.go文件

编译

go build命令表示将源代码编译成可执行文件。
在hello目录下执行:
go build
或者在其他目录执行以下命令:
go build hello

参考:https://www.liwenzhou.com/posts/Go/install_go_dev/