Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

up vote 5 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 updated the question to include a bit more info, specifically with the packages used. Packages I mean the ones called inside the go code. –  Luis May 10 at 18:13
Even though you got the answer correct and have more than 1K of points than me... this is not the end my friend... I WILL AVENGE THE REP RANKS!! YOU WILL FALL!! (Evil laughter fading in the background). BTW thanks for the answer. If you want, add this link since it includes adding the $GOPATH variable and other settings - youtube.com/watch?v=2KmHtgtEZ1s –  Luis May 10 at 18:20
Evil will triumph over simple mortals like you. Will email hdbgaf. Thanks buddy. –  Luis May 10 at 18:24

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.