- Remove any existing versions for a clean slate:
sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go
- Download and Install. Here I install version 1.14.2:
wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
sudo tar -xvf go1.14.2.linux-amd64.tar.gz
sudo mv go /usr/local
- Configure environment variables in
/etc/profile
:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
- Verify:
go version
- Create required GOPATH folders:
cd $HOME/go
mkdir bin pkg src
- Test Compilation:
mkdir github.com/karansinghgit/hello -p
cd github.com/karansinghgit/hello
go mod init
touch main.go
- Write the code -->
package main
import "fmt"
func main(){
fmt.Println("hello")
}
-
Run the file:
go run main.go
-
Enjoy