---
title: Installing Go on Ubuntu
description: This tutorial explains how to install the latest version of Go on an Ubuntu Instance
tags: Go Ubuntu Bionic-Beaver
products:
  - instances
dates:
  validation: 2024-10-03
  posted: 2018-08-14
  validation_frequency: 24
---
import Requirements from '@macros/iam/requirements.mdx'


[Go](https://go.dev/) is an open-source programming language, initially developed by a team at Google and becoming increasingly popular for many applications. The project is backed by many contributors from the open-source community.

This tutorial will guide you through the download and installation of the Go programming language on a Ubuntu Bionic Beaver server. At the end of this guide, you will create your first Go application.

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- An [SSH key](/organizations-and-projects/how-to/create-ssh-key/)
- An [Instance](/instances/how-to/create-an-instance/) running on Ubuntu Bionic Beaver (18.04)
- `sudo` privileges or access to the root user

## Installing Go

1. Connect to your Instance using [SSH](/instances/how-to/connect-to-instance/).
    ```
    ssh root@your_server_ip
    ```
2. Update your APT package cache and upgrade the software already installed on the Instance to the latest release.
    ```
    apt update && apt upgrade -y
    ```
3. Install the Go programming language from the apt repository:
    ```
    apt install golang -y
    ```
4. Make sure Go is installed by running the following command:
    ```
    go version
    ```

    You should see an output like the following:

    ```
    root@gopher:~# go version
    go version go1.22.2 linux/arm64
    ```
5. Set the `GOPATH` for your environment:
    ```bash
    echo "GOPATH=$HOME/golang" >> ~/.bashrc
    echo "export GOPATH" >> ~/.bashrc
    echo "PATH=\$PATH:\$GOPATH/bin # Add GOPATH/bin to PATH for scripting" >> ~/.bashrc
    source ~/.bashrc
    ```

## Creating a Hello World Go Application

1. Start by creating a workspace, where you will store the files of your project.
    ```
    mkdir -p $HOME/golang/src/hello-world
    ```
    <Message type="note">
      Go uses a strict [Workspace layout](https://go.dev/doc/code/#Workspaces). You should follow the guidelines to make sure your application will work.
    </Message>
2. Open a text editor and create a file `hello-world.go` in the working directory. Then copy and paste the following content into it:
    ```go
    package main

    import "fmt"

    func main() {
        fmt.Printf("Hello world! This is my first Go program.\n")
    }
    ```
3. Run the code directly in Go with the command `go run`:
    ```
    go run hello-world.go
    ```
4. Compile the application if you want to have a program directly available as a binary to distribute it.
    ```
    go install hello-world
    ```
5. Once the application is compiled, you can launch it by typing `hello-world` in your terminal.
    ```bash
    bill@golang:~# hello-world
    Hello world! This is my first Go program.
    ```
6. Use `which` to discover the location of the binary. It will return the file path:
    ```
    bill@golang:~# which hello-world
    /home/bill/golang/bin/hello-world
    ```

## Creating a Go web application

Go provides the [`net/http`](https://pkg.go.dev/net/http) package, which makes it very easy to create web applications:

Create a new workspace and add the following content to the **main.go**.

```go
go
package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", WorldServer)
    http.ListenAndServe(":8080", nil)
}

func WorldServer(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}
```

You now have a working Go development environment. If you want to learn more about writing code in Go, you can follow the [interactive tutorial](https://go.dev/tour/welcome/).