How to install Go on Linux Mint 18 18.1 and Ubuntu 16.04 16.10

Golang on Linux Mint 18

Go, or Golang, is an open source programming language from Google. Released in late-2009, it has since become a very popular programming language. Docker and many of its tools are written in Go.

Unlike Python, it doesn’t come pre-installed on most Linux distributions, but I expect that to change soon. Before then, installing it on your favorite Linux distribution is a breeze, as its installation packages are in official package repositories.

In this tutorial, we’ll go through the process of installing it on Linux Mint 18 and 18.1 and Ubuntu 16.04 and 16.10.

Install Go on Linux Mint and Ubuntu

To install Go, fire up a terminal and type the following commands:

# Install Go on Linux Mint 18/18.1 and Ubuntu 16.04/16.10

sudo apt install golang-go

#

That’s just what you need to install it. The Go executable is expected to be in /usr/local/go, but on both Linux Mint 18/18.1 and Ubuntu 16.04/16.10, it’s actually installed in another (custom) location – /usr/bin/go. Because its parent directory – /usr/bin – is already in your PATH. Nothing to worry about here. Go is ready to go.

Test you Go Installation

Here we’ll set up a Go workspace and build an Hello World! program. If Go can run it successfully, then Go is truly set to go. For this tutorial, I’m calling the workspace gostuff, create it and ensure that it’s in your PATH. The following commands show how to create the workspace:

# Create a Go workspace

mkdir ~/gostuff

# This will do the same thing

mkdir $HOME/gostuff

# 

Afterwards, set the GOPATH environment variable to point to the new workspace. The best approach to this is to set it in the .profile file under your home directory. The following commands show how to go about it:

# Open the .profile file

nano ~/.profile

# Set GOPATH environment variable by appending the next command to .profile 

export GOPATH=$HOME/gostuff

# Save and close the file, then activate it

source ~/.profile

#

With that out of the way, we’ll need to create the directory structure for a Go project using the following command:

# Create the Go project's directory structure
# Use the next command if you're using GitHub to manage your project
# Replace "user" with your username on GitHub

mkdir -p ~/gostuff/src/github.com/user/hello

# Use this if you're using GitLab. Replace "user" with your username on GitLab

mkdir -p ~/gostuff/src/gitlab.com/user/hello

# 

Inside the hello directory you created using the last command, create a file called hello.go and copy and paste the following code into it. All the code does is emit the famous Hello, world!.

# Create a file called hello.go

nano ~/gostuff/src/github.com/user/hello/hello.go

# Or

nano ~/gostuff/src/gitlab.com/user/hello/hello.go

# Copy and paste the following code into hello.go

package main

import "fmt"

func main() {
    fmt.Printf("Hello, world!\n")
}

# 

If this is getting to be too long, don’t worry, we’re almost home. But we won’t get there until we compile the Go code using the next command:

# Compile Go code
# If you went the path of GitHub, use this command

go install github.com/user/hello

# Use this if you went the path of GitLab

go install gitlab.com/user/hello

# 

If the code compiled successfully, there should now be an executable in the bin directory of your Go workspace. And if you run the command, you’ll get the expected output, as shown here:

# Run Go command

$GOPATH/bin/hello
# Output follows:
Hello, world!

# 

That’s it! You just installed Go on Linux Mint 18/18.1 or on Ubuntu 16.04/16.10 and verified that it works. To learn more about Go and how to start developing Go applications, click here.

Related Post:  Install Unity Tweak Tool on Ubuntu 14.10

Golang on Linux Mint 18

Share:

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on linkedin
LinkedIn

Hola! Did you notice that LinuxBSDos.com no longer run network ads?  Yep, no more ads from the usual suspects that track and annoy you across the Internet. But since I still need to pay to keep the site running, feel free to make a small donation by PayPal or your favorite cryptocurrency.

  • Bitcoin
  • Ethereum
  • Xrp
  • Bitcoin cash
  • Bitcoin sv
  • Litecoin
  • Binance coin
  • Cardano
  • Ethereum classic
Scan to Donate Bitcoin to bc1qzvlte2m224zkayhdc7fdfjkp2rsgt0l5a496ua

Donate Bitcoin to this address

Scan the QR code or copy the address below into your wallet to send some Bitcoin

Scan to Donate Ethereum to 0x0F4362DFF77F3Ba0Dc637F5f3Eba35D09a2fA60C

Donate Ethereum to this address

Scan the QR code or copy the address below into your wallet to send some Ethereum

Scan to Donate Xrp to r4ggjvL36njsMCYTkJ3S7cTHscPsMsSGQv

Donate Xrp to this address

Scan the QR code or copy the address below into your wallet to send some Xrp

Scan to Donate Bitcoin cash to qrs0dedzp9t55af3nfwypydghp29r0xguy9s20fz2k

Donate Bitcoin cash to this address

Scan the QR code or copy the address below into your wallet to send some Bitcoin cash

Scan to Donate Bitcoin sv to 15K9TLyVDBtLuG9cYvXCX9SSkq9C9oUKHK

Donate Bitcoin sv to this address

Scan the QR code or copy the address below into your wallet to send some Bitcoin sv

Scan to Donate Litecoin to LetJ9QQMb7u2LMZ9Tu6rtHwcBcQFW98fbG

Donate Litecoin to this address

Scan the QR code or copy the address below into your wallet to send some Litecoin

Scan to Donate Binance coin to bnb1ga8trq08ssqepd90v6225nzfgy448pu5pw8gxp

Donate Binance coin to this address

Scan the QR code or copy the address below into your wallet to send some Binance coin

Scan to Donate Cardano to addr1qx2354yw49etstfljpdhwja3ajjlt487lg95vu9ngy2q6vu4rf2ga2tjhqknlyzmwa9mrm997h20a7stgectxsg5p5esq5l7d9

Donate Cardano to this address

Scan the QR code or copy the address below into your wallet to send some Cardano

Scan to Donate Ethereum classic to 0xcD6CC972a2297FcafACDcfE042C55C69516a9264

Donate Ethereum classic to this address

Scan the QR code or copy the address below into your wallet to send some Ethereum classic

Subscribe for updates. Trust me, no spam!

Sponsored links

1. Attend Algorithm Conference, a top AI and ML event.
2. Reasons to use control panel for your server.
3. DHgate Computers Electronics, Cell Phones & more.

Upcoming events

5 Responses

  1. To compile this on Mint 18 I had to do the following
    $ go build hello.go

    This created the executable hello in the directory and then I just ran it.
    $ hello
    Hello, world!

    The github and gitlab compile commands wouldn’t work for me.

  2. Something is missing, not working Mint 18 version:

    madis@k* ~ $ cat /etc/linuxmint/info
    RELEASE=18
    CODENAME=sarah
    EDITION=”Cinnamon 64-bit”
    DESCRIPTION=”Linux Mint 18 Sarah”
    DESKTOP=Gnome
    TOOLKIT=GTK
    NEW_FEATURES_URL=http://www.linuxmint.com/rel_sarah_cinnamon_whatsnew.php
    RELEASE_NOTES_URL=http://www.linuxmint.com/rel_sarah_cinnamon.php
    USER_GUIDE_URL=help:linuxmint
    GRUB_TITLE=Linux Mint 18 Cinnamon 64-bit
    madis@k* ~ $ sudo apt install go
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package go

    1. Something weird happened between when I wrote that article and today. That package is no longer available. Crazy weird.

      Install the golang-go package instead, just as for Ubuntu sudo apt install golang-go.

Leave a Reply to MightyMoo Cancel reply

Your email address will not be published. Required fields are marked *

Get the latest

On social media
Via my newsletter

Partner links

1. Attend Algorithm Conference, a top AI and ML event for 2021.
2. Reasons to use control panel for your server.
3. DHgate Computers Electronics, Cell Phones & more.
Hacking, pentesting distributions

Linux Distributions for Hacking

Experts use these Linux distributions for hacking, digital forensics, and pentesting.

Categories
Archives

The authors of these books are confirmed to speak during

Algorithm Conference

T-minus AI

Author was the first chairperson of AI for the U.S. Air Force.

The case for killer robots

Author is the Director of the Center for Natural and Artificial Intelligence.

Why greatness cannot be planned

Author works on AI safety as a Senior Research Scientist at Uber AI Labs.