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!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

24,101FansLike
214FollowersFollow
10SubscribersSubscribe

LATEST ARTICLES

control android linux
Scrcpy is a desktop program that can be used to access your Android phone's system and interface through your computer. The app is quite convenient, and some of its best features are highlighted below.
manjaro complete usb drive
In this tutorial, we will show step by step how to install a Manjaro on a USB flash. For those new to this distro, it is a light-weight distro that is based on Arch Linux. Arch Linux is known for its simplistic approach and is typically made for Linux pros, but Manjaro bridges the gap between user-friendliness and rock-solid performance.
best linux distros for windows users
When Microsoft initially released Windows 7 in October 2009, the software giant committed to providing ten years of support for its popular operating system.  The much-maligned Microsoft was true to their word, support for Windows 7 ended just yesterday a little over ten years after its release.