DEV Community

Cover image for Install Go on Ubuntu: A Step-By-Step Guide

Install Go on Ubuntu: A Step-By-Step Guide

Go, also known as Golang, is a powerful programming language developed by Google. Known for its simplicity, efficiency, and robust concurrency support, Go has gained popularity among developers. If you're using Ubuntu as your operating system, this step-by-step guide will walk you through the process of installing Go on your machine.

Prerequisites to Install Go on Ubuntu

Before you begin the installation, make sure you have the following prerequisites in place:

  1. A machine running Ubuntu.
  2. Access to a terminal with administrative privileges.

How to Install Go on Ubuntu?

Here is the step-by-step for installing Go on Ubuntu:

Step 1: Update and Upgrade

Start by ensuring your system is up to date. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

This will update the package list and upgrade all installed packages on your system.

Need help regarding Software Installation and Setup? Consider contacting Server Support Experts.

Step 2: Downloading Go

Now, navigate to the official Go website to find the latest version of the language. Copy the download link for the Linux distribution. In your terminal, use wget to download the Go tarball:

wget https://golang.org/dl/goX.XX.X.linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

Replace X.XX.X with the latest version number available.

Step 3: Extracting the Tarball

Once the download is complete, extract the tarball using the following command:

sudo tar -C /usr/local -xzf goX.XX.X.linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

Step 4: Configuring Environment Variables

To use Go, you need to set up the PATH and GOPATH environment variables. Edit your profile configuration file using a text editor like nano:

nano ~/.profile
Enter fullscreen mode Exit fullscreen mode

Add the following lines at the end of the file:

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
Enter fullscreen mode Exit fullscreen mode

Save and exit the text editor. Then, apply the changes to your current session:

source ~/.profile
Enter fullscreen mode Exit fullscreen mode

Step 5: Verifying the Installation

To verify that Go has been installed successfully, run the following commands:

go version
Enter fullscreen mode Exit fullscreen mode

You should see the installed Go version printed in the terminal.

Quick Tip:

For comprehensive server support, including server setup, software installation, server management, and web hosting control panel management, consider engaging the expertise of Server Support Experts. Their professionals specialize in ensuring the optimal performance, security, and reliability of your server infrastructure.

How to Manage Go Versions with Go Version Manager (gvm)

Installing gvm

For better version management, you can use a tool like Go Version Manager (gvm). Install gvm with the following commands:

sudo apt-get install bison
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Enter fullscreen mode Exit fullscreen mode

Add the following line to your profile configuration:

[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
Enter fullscreen mode Exit fullscreen mode

Source your profile or restart the terminal:

source ~/.profile
Enter fullscreen mode Exit fullscreen mode

Installing Specific Go Versions

With gvm, you can easily install and switch between different Go versions. To install a specific version, use the following command:

gvm install goX.XX.X
Enter fullscreen mode Exit fullscreen mode

Conclusion

Congratulations! You've successfully installed Go on your Ubuntu machine. Whether you're a seasoned developer or just getting started, Go provides an efficient and versatile platform for building robust applications. Take advantage of Go's simplicity, concurrency support, and strong community to enhance your coding experience. If needed, gvm offers a convenient way to manage multiple Go versions, allowing you to switch between them effortlessly. Now, you're ready to dive into the world of Go programming on your Ubuntu system. Happy coding!

Top comments (0)