Installation
-
Start by moving into a writable directory:
$ cd /tmp
-
Use the curl command and the link from Go to download the tarball:
$ curl -LO https://dl.google.com/go/go1.12.7.linux-amd64.tar.gz
-
Confirm our download is valid. Run this command and make sure the output equals
66d83bfb5a9ede000e33c6579a91a29e6b101829ad41fffb5c5bb6c900e109d9
:$ sha256sum go1.12*.tar.gz
-
Install go.
$ sudo tar -C /usr/local -xvzf go1.12.7.linux-amd64.tar.gz
-
Setup our go folders.
$ mkdir -p ~/go/{bin,pkg,src}
-
Enable
Go
in your paths.$ sudo vi /etc/profile.d/path.sh
-
Append the following to the file.
export PATH=$PATH:/usr/local/go/bin
-
Open this file.
$ sudo vi ~/.bash_profile
-
Append the following:
export GOROOT=/usr/local/go export GOBIN="$HOME/go/bin" export GOPATH="$HOME/go"
-
Apply your changes.
$ source /etc/profile && source ~/.bash_profile
Usage
-
Create our new file.
$ vi ~/go/src/hello.go
-
Set the following content:
```go package main
import "fmt"
func main() { fmt.Printf("Hello, World!\n") } ```
-
Run our installation.
$ go install $GOPATH/src/hello.go
-
Run.
$ $GOBIN/hello
Notes
-
The following instructions where adapted from DigitalOcean.
-
Also special thanks to this article.