Chapter 1. Go

1.1. About Go Toolset

Go Toolset is a Red Hat offering for developers on the Red Hat Enterprise Linux platform. It provides the Go programming language tools and libraries. Go is alternatively known as golang.

Go Toolset is distributed as a part of Red Hat Developer Tools for Red Hat Enterprise Linux 7. Go Toolset is available as a module for Red Hat Enterprise Linux 8.

The following components are available as a part of Go Toolset:

Table 1.1. Go Toolset components

NameVersionDescription

golang

RHEL 7 — 1.15.11
RHEL 8 — 1.15.7

A Go compiler.

delve

RHEL 7 — 1.5.0
RHEL 8 — 1.5.0

A Go debugger.

1.2. Compatibility

Go Toolset is available for Red Hat Enterprise Linux 7 and Red Hat Enterprise Linux 8 on the following architectures:

  • AMD and Intel 64-bit architectures
  • The 64-bit ARM architecture (Only RHEL 8)
  • IBM Power Systems, Little Endian
  • IBM Power Systems, Big Endian (Only RHEL 7)
  • 64-bit IBM Z

1.3. Getting access to Go Toolset on Red Hat Enterprise Linux 7

This chapter lists the steps to perform before installing Go Toolset on a Red Hat Enterprise Linux 7 system. Complete the following steps to attach a subscription that provides access to the repository for Red Hat Developer Tools, and then enable the Red Hat Developer Tools and Red Hat Software Collections repositories.

Prerequisites

  • Verify that wget is installed on your system. The tool is available from the default Red Hat Enterprise Linux repositories. To install it, run the following command as root:

    # yum install wget

Procedure

  1. Get the latest subscription data from the server:

    # subscription-manager refresh
  2. Use the following command to register the system:

    # subscription-manager register

    You can also register the system by following the appropriate steps in Registering and Unregistering a System in the Red Hat Subscription Management document.

  3. Display a list of all subscriptions that are available for your system and identify the pool ID for the subscription:

    # subscription-manager list --available

    This command displays the subscription name, unique identifier, expiration date, and other details related to it. The pool ID is listed on a line beginning with Pool ID.

  4. Attach the subscription that provides access to the Red Hat Developer Tools repository. Use the pool ID you identified in the previous step.

    # subscription-manager attach --pool=<appropriate pool ID from the subscription>
  5. Verify the list of subscriptions attached to your system:

    # sudo subscription-manager list --consumed
  6. Enable the rhel-7-variant-devtools-rpms repository:

    # subscription-manager repos --enable rhel-7-variant-devtools-rpms

    Replace variant with the Red Hat Enterprise Linux system variant (server or workstation).

    Consider using Red Hat Enterprise Linux Server to access the widest range of the development tools.

  7. Enable the rhel-variant-rhscl-7-rpms repository:

    # subscription-manager repos --enable rhel-variant-rhscl-7-rpms

    Replace variant with the Red Hat Enterprise Linux system variant (server or workstation).

  8. Add the Red Hat Developer Tools key to your system:

    # cd /etc/pki/rpm-gpg
    # wget -O RPM-GPG-KEY-redhat-devel https://www.redhat.com/security/data/a5787476.txt
    # rpm --import RPM-GPG-KEY-redhat-devel

Once the subscription is attached to the system and the repositories are enabled, install Go Toolset as described in Section 1.4, “Installing Go Toolset”.

Additional Resources

  • For more information on how to register your system using Red Hat Subscription Management and associate it with subscriptions, see the Red Hat Subscription Management collection of guides.

1.4. Installing Go Toolset

Go Toolset is distributed as a collection of RPM packages that can be installed, updated, uninstalled, and inspected by using the standard package management tools that are included in Red Hat Enterprise Linux. Note that a valid subscription that provides access to the Red Hat Developer Tools content set is required to install Go Toolset on a Red Hat Enterprise Linux 7 system. For detailed instructions on how to associate your Red Hat Enterprise Linux 7 system with an appropriate subscription and get access to Go Toolset, see Section 1.3, “Getting access to Go Toolset on Red Hat Enterprise Linux 7”.

Important

Before installing Go Toolset, install all available Red Hat Enterprise Linux updates.

  1. Install all the components included in Go Toolset for your operating system:

    • On Red Hat Enterprise Linux 7, install the go-toolset 1.15 collection:

      # yum install go-toolset-1.15
    • On Red Hat Enterprise Linux 8, install the go-toolset module:

      # yum module install go-toolset

      This installs all development and debugging tools, and other dependent packages to the system.

  2. Choose a Go language workspace directory and save its location as an environment variable to the $HOME/.bashrc file:

    $ mkdir -p workspace_dir
    $ echo 'export GOPATH=workspace_dir' >> $HOME/.bashrc
    $ source $HOME/.bashrc

    Select an appropriate value for the workspace_dir directory. A common choice is $HOME/go.

    Use the -p flag with the mkdir command to create the workspace_dir directory along with the directories that lead to it.

    If the GOPATH variable is not set, the go compiler uses the ~/go directory.

Additional resources

  • Workspaces — A description of the Go language workspace organization in the official documentation for the Go programming language.

Installable documentation

To install the Go Toolset installable documentation, complete the following steps.

  • On Red Hat Enterprise Linux 7, install the go-toolset-1.15-golang-docs package:

    # yum install go-toolset-1.15-golang-docs

    The installable documentation will be installed to /opt/rh/go-toolset-1.15/root/usr/lib/go-toolset-1.15-golang/doc/docs.html.

  • On Red Hat Enterprise Linux 8, install the golang-docs package:

    # yum install golang-docs

    The installable documentation will be installed to /usr/lib/golang/doc/effective_go.html.

1.5. Additional resources

A detailed description of Go Toolset and all its features is beyond the scope of this book. For more information, see the resources listed below.

Online documentation