Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to correctly install and configure the Go Language in Ubuntu. There are many packages to choose from but which packages do I need to install and what do I need to configure afterwards to be able to use any of the Go packages without having a "cannot find package" error for example or any other basic errors of that kind.

I installed the golang package but do I need to install any additional ones or configure something else?

As an example try to run the following:

package main

import (

func HelloServer(w http.ResponseWriter, req *http.Request) {
    w.Header().Set("Content-Type", "text/plain")
    w.Header().Set("Connection", "keep-alive")
        w.Write([]byte("hello, world!\n"))
func main() {
        http.HandleFunc("/", HelloServer)
        log.Println("Serving at")
        http.ListenAndServe(":8080", nil)
share|improve this question
up vote 6 down vote accepted

Installing the golang metapackage should be enough:

sudo apt-get install golang

"This package is a metapackage that, when installed, guarantees that (most of) a full Go development environment is installed." So, after that all you need is type go help for basic commands:

Go is a tool for managing Go source code.


go command [arguments]

The commands are:

build       compile packages and dependencies
clean       remove object files
env         print Go environment information
fix         run go tool fix on packages
fmt         run gofmt on package sources
get         download and install packages and dependencies
install     compile and install packages and dependencies
list        list packages
run         compile and run Go program
test        test packages
tool        run specified go tool
version     print Go version
vet         run go tool vet on packages

Make a hello world in gedit. Example from their website:

package main

import "fmt"

func main() {
    fmt.Println("Hello world\n")

(save it as hello.go)

Executing ...

 go run hello.go

yields ...

 Hello world

gorun lets you use a she-bang. Do read this topic though. Above example can then be:

package main

func main() {
    println("Hello world!\n")

And making it executable:

chmod +x hello.go

yields ...

Hello world!

(I added the \n myself)

Your example has a mistake:

import http needs to be net/http

go run test.go
2014/05/10 20:15:00 Serving at
share|improve this answer

I have been using Golang for 2 week now and I want ot share how you can install the latest Go version (v1.3.1) on Ubuntu 13.x / 14.x.

Go V1.3

Default folder: /usr/lib/go

cd /usr/lib/
apt-get install mercurial
hg clone -u release
cd /usr/lib/go/src

Configure environment variables

ll /usr/lib/go
nano ~/.bashrc

# append this to your script
export GOPATH=/srv/go
if [ -d "/usr/lib/go/bin" ] ; then

[Update the GO Version via Version Control later if needed]

cd /usr/lib/go
hg update release

!!! Reconnect the SSH Terminal to execute the new .bashrc

Check the environment settings

go env

Create my dev environment. It can be anything so also ~/go/ if you want.

mkdir -p /srv/go
cd    /srv/go/
mkdir -p $GOPATH/src/


mkdir -p $GOPATH/src/
cd    $GOPATH/src/
nano hello.go

package main
import "fmt"
func main() {
    fmt.Printf("goeiedag, wereld\n")

Run it

go run hello.go

Build the binary and install it in $GOPATH/bin/

cd $GOPATH/src/
go install
ll $GOPATH/bin/
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.