How to Install Go on Ubuntu

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

What is Go?

Go is a compiled, statically typed programming language developed by Google. Many modern applications such as Docker, Kubernetes, and Caddy are written in Go.

Install Go

  1. Use curl or wget to download the current binary for Go from the official download page. As of this writing, the current version is 1.12.9. Check the download page for updates, and replace 1.12.9 with the most recent stable version if necessary.

     curl -O https://storage.googleapis.com/golang/go1.12.9.linux-amd64.tar.gz
    
  2. Verify the .tar file using sha256sum:

     sha256sum go1.12.9.linux-amd64.tar.gz
    
    aac2a6efcc1f5ec8bdc0db0a988bb1d301d64b6d61b7e8d9e42f662fbb75a2b9b  go1.12.9.linux-amd64.tar.gz
  3. Extract the tarball:

     tar -xvf go1.12.9.linux-amd64.tar.gz
    
  4. Adjust the permissions and move the go directory to /usr/local:

     sudo chown -R root:root ./go
     sudo mv go /usr/local
    

Adjust the Path Variable

  1. Using a text editor, open the ~/.profile file and add the following two lines to the bottom of the file:

    File: ~/.profile
    export GOPATH=$HOME/go
    export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
  2. Save the file, and load the commands into the current shell instance:

     source ~/.profile
    

Test the Installation

According to the official documentation, the following steps are the recommended way to test the success of the installation:

  1. In your home directory create a folder named go, this will be your workspace:

     mkdir go
    
  2. Within that directory create /src/hello and within that directory copy and paste the contents of the file below:

     mkdir -p go/src/hello && cd go/src/hello
     touch hello.go
    
    File: hello.go
    1
    2
    3
    4
    5
    6
    7
    
    package main
    
    import "fmt"
    
    func main() {
        fmt.Printf("hello, world\n")
    }
  3. Build the hello.go file:

     go build
    
  4. Run the script:

     ./hello
    
    hello, world

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.