# Ubuntu Install Go: How to Set Up a Clean Development Environment

> Install Go on Ubuntu with this guide. Learn to set up a clean development environment by removing the gold linker, installing dependencies, and configuring Go variables for building applications.

- Repository: [Go/go](https://github.com/golang/go)
- Tags: how-to-guide
- Published: 2026-02-16

---

**To install Go on Ubuntu correctly, remove the problematic gold linker, install build dependencies, then either extract the official binary to `/usr/local/go` or build from source using [`./make.bash`](https://github.com/golang/go/blob/main/./make.bash), ensuring you configure `GOROOT`, `GOPATH`, and `PATH` environment variables.**

Setting up a clean Go development environment on Ubuntu requires attention to system-level dependencies and linker compatibility. Whether you are building the Go toolchain from the `golang/go` source repository or running pre-compiled binaries, following the correct **ubuntu install go** procedure prevents common build failures and runtime errors.

## Prerequisites: System Packages and Linker Configuration

### Install Build Dependencies

Begin by updating package lists and installing the essential build tools that Go requires for compilation:

```bash
sudo apt-get update
sudo apt-get install -y build-essential curl git

```

The `build-essential` package provides `gcc`, `make`, and other compilers that the Go toolchain uses when building from source or compiling cgo-enabled packages.

### Remove the Gold Linker to Prevent Build Failures

Ubuntu ships with the **gold** linker (`binutils-gold`), which is incompatible with Go builds. The repository’s [`src/make.bash`](https://github.com/golang/go/blob/main/src/make.bash) explicitly detects gold linker version 2.20 and aborts with instructions to remove it. According to lines 98–106 in [`src/make.bash`](https://github.com/golang/go/blob/main/src/make.bash), you must run:

```bash
sudo apt-get remove -y binutils-gold

```

Skipping this step results in build failures when compiling Go from source or when the toolchain attempts to link binaries.

## Method 1: Install Official Go Binary (Recommended)

Downloading the official pre-compiled binary ensures you receive the latest stable release without compilation overhead.

### Download and Extract the Tarball

Retrieve the latest Linux tarball and extract it to `/usr/local`, the conventional location for system-wide tools:

```bash
curl -LO https://go.dev/dl/go1.23.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.23.0.linux-amd64.tar.gz

```

### Configure Environment Variables

Add Go to your `PATH` and define workspace variables in your profile. The standard practice uses `$HOME/go` as your `GOPATH`:

```bash
echo 'export PATH=$PATH:/usr/local/go/bin' >> $HOME/.profile
echo 'export GOPATH=$HOME/go'           >> $HOME/.profile
echo 'export GOBIN=$GOPATH/bin'        >> $HOME/.profile
source $HOME/.profile

```

### Verify the Installation

Confirm the toolchain is accessible and environment variables are set correctly:

```bash
go version          # Output: go version go1.23 linux/amd64

go env GOROOT GOBIN # Verify paths match your configuration

```

## Method 2: Build Go from Source

Building from the `golang/go` repository provides the latest development features and is necessary when contributing to the language itself.

### Clone the Repository

Create the source tree in the standard location:

```bash
git clone https://github.com/golang/go.git $HOME/go/src
cd $HOME/go/src

```

### Bootstrap the Toolchain

The [`src/make.bash`](https://github.com/golang/go/blob/main/src/make.bash) script orchestrates the build process, including downloading a previous Go release (`GOROOT_BOOTSTRAP`) required for bootstrapping:

```bash
cd src
./make.bash

```

If no existing Go installation exists, the script searches for bootstrap versions in `$HOME/go1.24.6`, `$HOME/sdk/go1.24.6`, or similar paths, failing with a descriptive error if none are found.

### Configure PATH for Source Build

Add the newly compiled binary to your environment:

```bash
echo 'export PATH=$PATH:$HOME/go/src/go/bin' >> $HOME/.profile
source $HOME/.profile

```

### Confirm the Build Succeeded

Check that the development version is active:

```bash
go version  # Output resembles: go1.24.6-dev

```

## Understanding Go Workspace Structure

A clean **ubuntu install go** setup requires distinguishing between three critical environment variables:

- **GOROOT**: Location of the Go installation itself (`/usr/local/go` for binaries, `$HOME/go/src` for source builds). This contains the standard library and compiler.
- **GOPATH**: Root of your Go workspace (conventionally `$HOME/go`). This directory contains your `src/`, `pkg/`, and `bin/` subdirectories for project code and dependencies.
- **GOBIN**: Directory where `go install` places compiled binaries (typically `$GOPATH/bin`).

Mixing multiple `GOROOT` values or leaving stale binaries in `GOBIN` causes "cannot find package" errors or runtime mismatches.

## Testing Your Installation with a Sample Application

Verify the complete development cycle by creating a minimal program:

```bash
mkdir -p $HOME/go/src/hello
cat > $HOME/go/src/hello/main.go <<'EOF'
package main

import "fmt"

func main() {
    fmt.Println("Hello, Ubuntu Go!")
}
EOF

cd $HOME/go/src/hello
go build          # Produces ./hello executable

./hello           # Prints: Hello, Ubuntu Go!

go run .          # Same output via the go tool

```

Successful execution confirms that compilation, linking, and runtime components function correctly.

## Maintaining and Updating Your Go Installation

**Binary installations:** Monitor the Go download page for new releases. When upgrading, remove the existing `/usr/local/go` directory before extracting the new tarball to prevent stale standard library files.

**Source installations:** Pull the latest changes and rebuild:

```bash
cd $HOME/go/src
git pull
./make.bash

```

The [`src/make.bash`](https://github.com/golang/go/blob/main/src/make.bash) script automatically handles incremental rebuilds and bootstrap version checks.

## Key Source Files in golang/go

Understanding the implementation details helps troubleshoot installation issues:

| File | Purpose | Relevance to Ubuntu Setup |
|------|---------|---------------------------|
| [`src/make.bash`](https://github.com/golang/go/blob/main/src/make.bash) | Primary build script containing the gold linker detection (lines 98–106) and bootstrap logic. | Critical for source builds; enforces removal of `binutils-gold`. |
| [`src/cmd/go/internal/work/exec.go`](https://github.com/golang/go/blob/main/src/cmd/go/internal/work/exec.go) | Handles execution of external commands during `go build` and `go run`. | Ensures compiled binaries execute correctly on Ubuntu. |
| [`src/cmd/go/alldocs.go`](https://github.com/golang/go/blob/main/src/cmd/go/alldocs.go) | Generates documentation for the `go` command-line tool. | Reference for environment variables and flags. |
| [`src/runtime/sys_linux.go`](https://github.com/golang/go/blob/main/src/runtime/sys_linux.go) | Linux-specific runtime implementations. | Ensures goroutine scheduling and system calls work correctly on Ubuntu kernels. |

## Summary

- **Remove `binutils-gold`** before installing, as enforced by [`src/make.bash`](https://github.com/golang/go/blob/main/src/make.bash) lines 98–106 in the golang/go repository.
- **Install dependencies** via `sudo apt-get install build-essential curl git`.
- **Choose your method**: Official binaries (extract to `/usr/local/go`) for stability, or source build ([`./make.bash`](https://github.com/golang/go/blob/main/./make.bash)) for development versions.
- **Configure environment variables**: Set `PATH` to include `go/bin`, define `GOPATH` (typically `$HOME/go`), and `GOBIN` (`$GOPATH/bin`).
- **Verify with a test program** using `go build` and `go run` to ensure the complete toolchain functions.

## Frequently Asked Questions

### How do I completely uninstall Go from Ubuntu?

To remove a binary installation, delete the `/usr/local/go` directory and remove the Go-related lines from your `~/.profile` or `~/.bashrc`. For source builds, delete the `$HOME/go/src` directory. Finally, run `source ~/.profile` to clear environment variables from your current session.

### Why does building Go from source fail with a gold linker error?

The build fails because Ubuntu’s `binutils-gold` package is incompatible with Go’s linker requirements. According to [`src/make.bash`](https://github.com/golang/go/blob/main/src/make.bash) lines 98–106 in the golang/go repository, the build script explicitly detects gold linker version 2.20 and aborts with instructions to run `sudo apt-get remove binutils-gold`.

### Should I use the binary install or build from source for production servers?

Use the official binary install for production servers. Pre-compiled binaries from go.dev provide stable, tested releases that install cleanly into `/usr/local/go`. Building from source is intended for Go language development, testing unreleased features, or contributing to the golang/go repository, and introduces unnecessary complexity for application deployment.

### What is the difference between GOROOT and GOPATH?

`GOROOT` specifies the location where Go is installed—containing the compiler, standard library, and toolchain binaries (`/usr/local/go` for binary installs). `GOPATH` defines your workspace for Go projects—containing your source code (`src/`), compiled packages (`pkg/`), and installed binaries (`bin/`). As of Go 1.11+, `GOPATH` is less critical for module-based projects, but `GOROOT` remains essential for all installations.