How to download and install Go Lang in Ubuntu 14.04/Ubuntu 16.04/Ubuntu 18.04/Linux?
For all those who are new to Go or go lang, here is how you can install go lang on your system and run your first GO program.
DOWNLOADING AND SETTING UP ENVIRONMENT VARIABLES
- Open terminal
- First update and upgrade your system using the following commands.
sudo apt-get update
sudo apt-get -y upgrade - Now download Go using the following command:
wget https://dl.google.com/go/go1.10.1.linux-amd64.tar.gz - Now to go to your Downloads folder and extract the package using the command:
sudo tar -xvf go1.10.1.linux-amd64.tar.gz - Next we move it to /usr/local using the command:
sudo mv go /usr/local - Now we need to setup environment variables use the following commands:
sudo nano ~/.profile - Add path:
export GOROOT=/usr/local/go
export GOPATH=$HOME/Projects
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH - Verify your installation by typing in the terminal
go version - Your go working directory has been set to Projects folder
RUNNING YOUR FIRST GO PROGRAM
- Change your present working directory and move to Projects folder
cd /Projects - Make three folders in the parent Projects folder
mkdir bin
mkdir pkg
mkdir src - Move into the src folder and open any text editor
cd /src
gedit - Type your first go program
package main
import “fmt”
func main() {
fmt.Println(“Hello World”)
} - Save the program by the name hello.go in the src folder
- Now in your /Projects/src type the following command
go run hello.go - You will see your output on terminal as Hello World.
All Commands summarised:
Here are all the commands for installation at one place that you can copy and paste directly and get started with GO:
- sudo apt-get update
- sudo apt-get -y upgrade
- wget https://dl.google.com/go/go1.10.1.linux-amd64.tar.gz
- cd Downloads
- sudo tar -xvf go1.10.1.linux-amd64.tar.gz
- sudo mv go /usr/local
- sudo nano ~/.profile
- export GOROOT=/usr/local/go
export GOPATH=$HOME/Projects
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH - go version
- cd /Projects
- mkdir bin
mkdir pkg
mkdir src - cd /src
gedit - package main
import “fmt”
func main() {
fmt.Println(“Hello World”)
} - go run hello.go