Golang开发环境安装
前言
安装之前,首先我也是全新的go语言学习者,我之前主职是Java;我这里也不做太多的说明,直接上安装教程,感觉还是挺简单
下载
先去这个地址下载安装包 https://golang.org/dl/, 本教程使用的版本是go1.12.5,基于centos7 linux来安装的,windows下
的安装很简单,我就不上教程了。
下载如图
可以右键链接地址复制地址使用wget https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
的方式,我就使用的这种方式
# wget https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
# ls
go1.12.5.linux-amd64.tar.gz
解压
# tar -xzvf go1.12.5.linux-amd64.tar.gz
# ls
go go1.12.5.linux-amd64.tar.gz
# cd go
# pwd
/usr/local/go
设置系统PATH
下面的命令必须以root身份运行或通过sudo
添加/usr/local/go/bin到PATH环境变量,这里通过修改.bashrc文件,还有其他的方式,可自行尝试哦
# vim ~/.bashrc
在最后一行添上
export PATH=/usr/local/go/bin:$PATH
输入source ~/.bashrc
生效环境
安装完成
输入go --help
# go --help
Go is a tool for managing Go source code.
Usage:
go [arguments]
The commands are:
bug start a bug report
build compile packages and dependencies
clean remove object files and cached files
doc show documentation for package or symbol
env print Go environment information
fix update packages to use new APIs
fmt gofmt (reformat) package sources
generate generate Go files by processing source
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages or modules
mod module maintenance
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet report likely mistakes in packages
Use "go help " for more information about a command.
Additional help topics:
buildmode build modes
c calling between Go and C
cache build and test caching
environment environment variables
filetype file types
go.mod the go.mod file
gopath GOPATH environment variable
gopath-get legacy GOPATH go get
goproxy module proxy protocol
importpath import path syntax
modules modules, module versions, and more
module-get module-aware go get
packages package lists and patterns
testflag testing flags
testfunc testing functions
Use "go help " for more information about that topic.
其他系统安装
macOS包安装程序
下载包文件,打开它,然后按照提示安装Go工具。该软件包将Go分发安装到/usr/local/go。
包应该将/usr/local/go/bin目录放在 PATH环境变量中。您可能需要重新启动任何打开的终端会话才能使更改生效。
windows下安装
Go项目为Windows用户提供了两个安装选项(除了从源代码安装):一个zip存档,需要您设置一些环境变量和一个MSI安装程序,它自动配置您的安装。
MSI安装程序
打开MSI文件, 然后按照提示安装Go工具。默认情况下,安装程序将Go分发放入c:\Go。
安装程序应将c:\Go\bin目录放在 PATH环境变量中。您可能需要重新启动任何打开的命令提示才能使更改生效。
Zip安装
下载zip文件并将其解压缩到您选择的目录中(我们建议c:\Go)。
将bin目录添加到(例如,c:\Go\bin)添加到PATH环境变量中。
在Windows下设置环境变量
在Windows下,您可以通过“系统”控制面板的“高级”选项卡上的“环境变量”按钮设置环境变量。某些版本的Windows通过“系统”控制面板内的“高级系统设置”选项提供此控制面板