How to download and install Go Lang in Ubuntu 14.04/Ubuntu 16.04/Ubuntu 18.04/Linux?

Shreya Singh
2 min readMay 31, 2018

--

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

  1. Open terminal
  2. First update and upgrade your system using the following commands.
    sudo apt-get update
    sudo apt-get -y upgrade
  3. Now download Go using the following command:
    wget https://dl.google.com/go/go1.10.1.linux-amd64.tar.gz
  4. Now to go to your Downloads folder and extract the package using the command:
    sudo tar -xvf go1.10.1.linux-amd64.tar.gz
  5. Next we move it to /usr/local using the command:
    sudo mv go /usr/local
  6. Now we need to setup environment variables use the following commands:
    sudo nano ~/.profile
  7. Add path:
    export GOROOT=/usr/local/go
    export GOPATH=$HOME/Projects
    export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
  8. Verify your installation by typing in the terminal
    go version
  9. Your go working directory has been set to Projects folder

RUNNING YOUR FIRST GO PROGRAM

  1. Change your present working directory and move to Projects folder
    cd /Projects
  2. Make three folders in the parent Projects folder
    mkdir bin
    mkdir pkg
    mkdir src
  3. Move into the src folder and open any text editor
    cd /src
    gedit
  4. Type your first go program
    package main
    import “fmt”
    func main() {
    fmt.Println(“Hello World”)
    }
  5. Save the program by the name hello.go in the src folder
  6. Now in your /Projects/src type the following command
    go run hello.go
  7. 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:

  1. sudo apt-get update
  2. sudo apt-get -y upgrade
  3. wget https://dl.google.com/go/go1.10.1.linux-amd64.tar.gz
  4. cd Downloads
  5. sudo tar -xvf go1.10.1.linux-amd64.tar.gz
  6. sudo mv go /usr/local
  7. sudo nano ~/.profile
  8. export GOROOT=/usr/local/go
    export GOPATH=$HOME/Projects
    export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
  9. go version
  10. cd /Projects
  11. mkdir bin
    mkdir pkg
    mkdir src
  12. cd /src
    gedit
  13. package main
    import “fmt”
    func main() {
    fmt.Println(“Hello World”)
    }
  14. go run hello.go

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Shreya Singh
Shreya Singh

Written by Shreya Singh

Software Development Engineer at Amazon, Google APAC Women Techmaker Scholar, C.S.E. Graduate @ NIT Patna

Responses (1)

Write a response