Skip to content

Instantly share code, notes, and snippets.

@karansinghgit
Last active July 1, 2020 16:14
Show Gist options
  • Save karansinghgit/ee10020fc40bd90f68cb659a21ce2492 to your computer and use it in GitHub Desktop.
Save karansinghgit/ee10020fc40bd90f68cb659a21ce2492 to your computer and use it in GitHub Desktop.
  1. Remove any existing versions for a clean slate:
sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go
  1. 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
  1. Configure environment variables in /etc/profile:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
  1. Verify:
go version
  1. Create required GOPATH folders:
cd $HOME/go
mkdir bin pkg src
  1. Test Compilation:
mkdir github.com/karansinghgit/hello -p
cd github.com/karansinghgit/hello
go mod init 
touch main.go
  1. Write the code -->
package main

import "fmt"

func main(){
	fmt.Println("hello")
}
  1. Run the file: go run main.go

  2. Enjoy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment