Let’s Go! – Installing the Go programming language on Debian

Go keeps growing and increasing in popularity as it evolves, leaving many to wonder if it is the eventual replacement of programming languages such as Python, Java, C++, and others.

Go, also referred to as Golang, is an open-source, lower-level, statically typed programming language created by Google.

A team of Google programmers (Robert Griesemer, Rob Pike, and Ken Thompson) developed Go in 2007.  Go’s primary purpose is building fast, simple, efficient, and reliable server-side and web-based applications.

Some commonly known open source applications written with Go include Dockers, Lime, InfluxDB, Kubernetes, etcd, and Terraform.  Go keeps growing and increasing in popularity as it evolves, leaving many to wonder if it is the eventual replacement of programming languages such as Python, Java, C++, and others.

“[Go] really feels like “the C for the 21st century.”

– Petr Hosek, Google Senior Software Engineer

Installing Go

Installing Go on your Linux distro is effortless.

Installing Go is effortless.
Installing Go is effortless.

Open a terminal window (<Ctrl><Alt>T).  At the command prompt, enter:

# sudo apt-get install golang

Press Y when prompted.

Configuring Golang Environment

Before using Go, we must first configure and setup our environment.

First, we must edit our ~/.profile file to add a GOPATH variable and add our Go working subdirectory to our PATH.

Edit ~/.profile file to add the GOPATH variable Go working subdirectory PATH.
Edit ~/.profile file to add the GOPATH variable Go working subdirectory PATH

Use your favorite text editor and add the following lines:

to the end of ~/.profile.  When satisfied with your edits, save the file.

Next, we need to load our new PATH variables into our current shell instance.

Reload the new PATH variables current shell instance.
Reload the new PATH variables’ current shell instance

# source ~/.profile

Although our updated PATH is loaded, we still have to create the subdirectory it refers to.

Create the Go working and project directories.
Create the Go working and project directories

# mkdir -p golang/src/sample && cd golang/src/sample

Notice that the first command (mkdir -p golang/src/sample) creates both directories that we need for our Go environment

  • The workspace directory (~./golang/src).
  • The project directory (~./golang/src/sample), where ‘sample‘ is our project directory.  Each Go project you create should have its subdirectory within ~./golang/src.

Of course, the second part of your command merely changes us to our project directory (~./golang/src/sample).

Create and Test Your First Go Program

Now, let’s create and test our first program.  Since we’re already in our project directory, use the text editor to create our first project source file.

Creating our first Go program.
Creating our first Go program

Add the following lines to the blank file:

package main

import "fmt"

func main() {
fmt.Printf("Hello, FOSS Linux Readers!n")

Save your file as sample.go.  Now let’s compile our new program.

Compiling our sample Go profile.
Compiling our sample Go profile

While still in the ~./golang/src/sample subdirectory, enter

# go build

After our program compiles, let’s test it.

Running ./sample - Hello FOSS Linux Readers!
Running ./sample – “Hello FOSS Linux Readers!”

# ./sample

Congratulations!  You’ve just built and successfully tested your first Go program.  Exciting isn’t it!

The Go programming language offers Linux users a great tool to not only learn a new programming language (or programming in general) but also allows for the quick creation of simple programs. They run fast and efficiently, not only in the Linux environment but also in Mac, Windows, and Android environments, as Go is a cross-platform language.

If so inclined, please install and test out Go.  ‘Go‘ ahead and create more sample programs with Go. Let us know how it turns out.

Here are a few websites to help you on your journey:

Good luck!

Travis Rose
Hi, I'm M Travis Rose, a contributor to FOSS Linux. I have over thirty years of experience in the IT arena, at least fifteen of which has been working with Linux. I enjoy converting existing Windows users to the wonderful world of Linux. I guess you could call me a Linux-evangelist. Long live Linux!


Please enter your comment!
Please enter your name here




cool and fun linux commands
The real purpose of this article is to help Linux newbies get comfortable and confident with the Linux command-line.  While knowledge and comfort of the Linux GUI allow great power, it is the mastery of the command line, or CLI, affords the Linux user unlimited power and certifies them as a Linux power user well on their way to becoming an expert.
screen capture apps linux
Do you want to make a video tutorial for YouTube or show-off your epic victory royale to your friends? Look no further — as we have compiled the 10 Best Screen Capturing Software for Linux. Whether you need to record your desktop screen or take a simple screenshot, FOSSLinux has got your back.
best video players for linux
Most Linux-based systems come with a built-in video player, but let's be honest, it most definitely won't be able to satisfy all of your requirements, due to the fact that default software is mostly made for basic purposes. In this article, we will review the 5 Best Video Players for Linux and thoroughly discuss their features as well as their pros and cons.