The Go programming language was created in 2007 at Google. Many projects are created in Golang including Docker, Kubernets, Gogs, InfluxDB and others.
The Go language can be used on various operating systems including Linux systems, Windows, Mac OS X and FreeBSD. You can even run it online, from your browser.
Installing Go
The Go language is a brand new static type development language with automatic garbage collection, rich built-in types, function multiple return values, error handling, anonymous functions, concurrent programming and reflection, and features such as simplicity, security, concurrency, and open source.
If you have a package manager, you can install it from a repository.
Ubuntu / Debian Linux
Install a set of tools to run Go programs.
apt-get install golang-go
CentOS 7 / Redhat Linux
If you use Redhat or CentOS, you can use yum to install go
yum install golang golang-godoc golang-vet golang-src golang-pkg-linux-amd64 -y
Windows
Installing under Windows systems, download
You can choose the local installation directory: D:\Go
,
add the D:\Go\bin
directory to the PATH environment
variable.
Set
$GOPATH=D:\goproject and $GOROOT=D:\Go\.
On CMD, enter go version
, which shows that the go run
environment has been successfully installed:
$GOPATH
allows multiple directories, when more than one
directory is available, attention to separators, multiple directories
when Windows is a semicolon; the packages that go get are stored in the
first directory by default when more than one $GOPATH is available.
The $GOPATH
catalog convention has three
subdirectories
The src
storage source code (such as .go. c .h .s, etc.)
executes the current working path of commands such as
go run
, go install
, etc. according to Go
default (that is, executing the above command under this path).
The intermediate file generated when the pkg compiles, such as:
.a
the executable file that is generated after the bin
compilation, can then try the code compilation to run.
From source
UNIX/Linux/Mac OS X, and using the source code installation method under the FreeBSD system:
Download source package:
go1.11.linux-amd64.tar.gz
.Extract the downloaded source package to the
/usr/local
directory.
tar -C /usr/local -xzf go1.11.linux-amd64.tar.gz
- add the
/usr/local/go/bin
directory to the PATH environment variable:
export PATH=$PATH:/usr/local/go/bin
Manual install
For other systems, you can run a manual install.
Running go online
You can run golang programs online on the Go Playground. On that page simply type your code and click run.
Check version
To check the current version of Golang, you can use the command.
[root@master ~]# go version
This command returns something like:
$ go version
go version go1.12.10 linux/amd64
If you get this output, Go has been installed successfully.