What is GOROOT and GOPATH and the problem of go path export. I have been through this many times and have seen lot of people struggling to fix this. In this small post I will tell you how to fix this problem. Lets see what is GOROOT and GOPATH?
How to install go latest version?
curl -O https://storage.googleapis.com/golang/go1.11.2.linux-amd64.tar.gz tar -xvf go1.11.2.linux-amd64.tar.gz sudo mv go /usr/local /usr/local/go/bin/go --version
This will give you the version of golang present. Still you cannot start working as this binary is not present in the path of the system environment variables. To add it in path you can simply follow the below instructions. It will give a small hint of what paths are needed and how to fix it. It will add in bashrc file so that you don’t have to do it again and again.
What is GOROOT and GOPATH?
What is GOROOT?
GOROOT is the directory where your actual binary for golang resides. So if you have to install go. You download the package, extract it and place in this location.
What is GOPATH?
GOPATH can be the working directory of your go projects. What ever you install through go get will be installed in this directory in `src` folder
How to FIx it?
Open your .bashrc or .bash_profile and write this lines at the end now the next time you will open terminal your life will be sorted.
export GOROOT=/usr/local/go export GOPATH=$HOME/yourprojectslocation export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
This will fix your problem and you can start writing awesome code in golang. You can also find the script to install go here.
If you find any problem please revert. We will fix it together. Also if you have important code snippets that can help other please contribute to this repository. CODE_SNIPPETS
Have a look at my recent learning project in golang.
If you don’t know go and want to learn I will recommend going through gotour which is awesome for the beginners.
Also read about
Tooling in Devops: Using Terraform For Automating Infrastructure
Working on Scale: Infrastructure Automation with terraform and chef.