A Comprehensive Guide to Install Go on Ubuntu[22 Easy Steps]

Written by

Reviewed by

Last updated: June 25, 2023

Expert verified

SVG Image

TL;DR

Here is a step-by-step guide to install Go on Ubuntu:

  1. Update system packages using the command sudo apt update.
  2. Upgrade the system packages to the latest versions by using the command sudo apt upgrade -y for improved stability and security.
  3. To install Go on Ubuntu, you need to download and extract the latest stable release from the official website.
  4. Add the Go binaries to the system’s PATH variable to access them conveniently from any directory.
  5. Apply the changes to the shell session to make the updated configuration effective.
  6. Check the Go version by running the command go version to confirm the installation’s success.

To install Go on Ubuntu, you may encounter four common errors: incorrect paths or environment variables, conflicts with existing installations, insufficient disk space, and incorrect permissions on the installation directory. To resolve these errors, ensure correct path and variable setup, handle conflicting versions, check and free up disk space, and adjust permissions on the installation directory. 

Continue reading the guide below to learn to install Go on Ubuntu and the common errors you may encounter during installation.


Go, also known as Golang, is an open-source programming language developed by Google. Its design philosophy focuses on simplicity, efficiency, and concurrency. With its clean and concise syntax, Go allows you to write elegant and readable code, making development a breeze. But Go’s appeal goes beyond its aesthetics; it offers a myriad of benefits that set it apart from other languages. In this article, I will walk you through the process to installing Go on Ubuntu, and I will also discuss four common errors with their possible solutions.

How to Install Go on Ubuntu 

To install Go on Ubuntu, you only need a 64-bit version of Ubuntu, at least 2GB of RAM, and ample disk space. These minimal system requirements ensure a seamless installation and optimal performance when utilizing Go on your Ubuntu system. Follow these steps:

  1. Open a Terminal and execute the following command to update system packages:
<strong>sudo apt update</strong>
  1. The command will update your system packages.
updating system packages
  1. Run the following command to upgrade your system:
<strong>sudo apt upgrade -y</strong>
  1. This will upgrade your system packages, ensuring you have the latest software.
upgrading system packages 1
  1. Visit the official Go website by clicking here.
visit official website of go
  1. On the Go page, locate the latest stable release compatible with Ubuntu. Click on the appropriate download link to begin the download.
downloading stable version of Go
  1. Open a Terminal and navigate to the directory where you downloaded the Go package.
navigating to directory
  1. Extract the package using the following command:
<strong>sudo tar -C /usr/local -xf goVERSION.linux-amd64.tar.gz</strong>

Replace VERSION with the version number you downloaded.

command to install go on ubuntu
  1. Next, you need to add Go binaries to your system’s PATH variable. Open the .profile file using a text editor:
<strong>nano ~/.profile</strong>
  1. This command will open the .profile file in the nano editor.
opening system PATHs
  1. Append the following lines at the end of the file:
<strong>export PATH=$PATH:/usr/local/go/bin</strong>
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
  1. Save the changes and exit the text editor.
adding go binaries to system PATH
  1. Finally, apply the changes to your current shell session by executing the following command:
<strong>source ~/.profile</strong>
  1. Now you have successfully installed Go on Ubuntu.
applying changes to current shell session
  1. To ensure Go functions properly, you need to set up the necessary environment variables. Execute the following command to create the Go workspace directory:
<strong>mkdir -p $HOME/go</strong>
  1. The output will be:
creating workspace directory for go
  1. Next, append the Go environment variables to the .profile file:
<strong>echo "export GOPATH=\$HOME/go" >> ~/.profile</strong>
echo "export PATH=\$PATH:\$GOPATH/bin" >> ~/.profile
  1. Save the changes and exit the text editor.
appending go environment variables
  1. Apply the changes to your current shell session by executing the following command:
<strong>source ~/.profile</strong>
  1. Your environment is now properly configured for Go development on Ubuntu.
save the changes
  1. To ensure Go is correctly installed, execute the following command to check the Go version:
<strong>go version</strong>
  1. The output should display the installed Go version, confirming a successful installation.
verifying go installation

4 Common Errors When Installing Go on Ubuntu

When installing Go on Ubuntu, there are four common errors that you may encounter. Remember, persistence and attention to detail will help you overcome these common errors and successfully install Go on Ubuntu. Here are four of them, along with some suggestions on how to resolve them:

  • 🔍 Incorrect Paths or Environment Variables: One common error is setting up incorrect paths or environment variables. Double-check that you have correctly specified the paths for Go binaries and added them to your system’s PATH variable. Ensure that the environment variables are properly set in your .bashrc or .profile file. If you’re unsure, consult the installation instructions or official documentation for the correct configuration. If you find that the paths or variables are incorrect, edit the respective configuration file using a text editor like nano ~/.bashrc or nano ~/.profile. Update the necessary lines with the correct paths and save the changes.
  • 🔄 Conflicts with Existing Installations: Conflicts may arise if multiple versions of Go or other programming languages are installed on your system. Ensure that no conflicting versions or installations could interfere with the Go installation process. You can use the which go command to check the current Go installation and go version to verify the installed version matches your desired version. If conflicts are present, consider uninstalling the conflicting versions using the appropriate package manager commands, such as sudo apt remove <package-name>.
  • 📥 Insufficient Disk Space: One common error you may encounter during the installation of Go is running out of disk space. Go requires a certain amount of disk space to be available for the installation process. If you encounter this error, check your disk space using the command df -h. If the available space is low, consider freeing up disk space by deleting unnecessary files or expanding your storage capacity.
  • ⚙️ Incorrect Permissions on Installation Directory: Another common error is having incorrect permissions on the installation directory. When installing Go, it’s essential to ensure that the installation directory and its subdirectories have the proper permissions for read, write, and execute access. If you encounter permission-related errors, you can resolve them by running the following command to change the ownership of the Go installation directory, sudo chown -R $(whoami) /usr/local/go. This command changes the ownership of the /usr/local/go directory to the current user, allowing you to have the necessary permissions to work with Go files and directories.

To Sum Up

I hope this step-by-step guide has helped you successfully install Go on Ubuntu system. With Go now up and running, you’re ready to explore the world of efficient and powerful programming. I have also discussed common errors and possible solutions that may occur during go installation.

To further enhance your Go programming skills, I recommend diving into the following articles, Optimizing Go Performance, Building Scalable Web Applications with Go, and Advanced Go Concurrency. Continuously expanding your knowledge through these resources will accelerate your growth as a proficient Go developer on the Ubuntu platform.

Frequently Asked Questions

Can I install Go on Ubuntu using a package manager?

While Ubuntu’s default package manager, apt, does not provide the latest Go versions, you can still install Go on Ubuntu using package managers specifically designed for Go, such as apt-get. These Go-specific package managers install and manage Go packages, including updates and dependencies. They ensure that you have the latest version of Go and provide a seamless experience for managing your Go projects. Some popular Go package managers compatible with Ubuntu include apt-get, snap, and gimme. To install Go using a package manager, refer to the respective documentation and installation guides for detailed instructions tailored to your chosen package manager.

How can I uninstall a specific version of Go on Ubuntu?

To uninstall a specific version of Go on Ubuntu, identify the installation directory of the version you want to remove. Open a Terminal and execute the command sudo rm -rf {{INSTALLATION_DIRECTORY}}, replacing {{INSTALLATION_DIRECTORY}} with the actual path. This deletes the directory and its contents. Update your environment variables by modifying or removing the relevant lines in the .profile file. Save the changes, exit the text editor, and execute source ~/.profile to apply the updates. Following these steps ensures the clean removal of the specific Go version while preserving other installations on Ubuntu.

Can I use Go for web development on Ubuntu?

Absolutely! Go is well-suited for web development on Ubuntu. Its simplicity, efficient concurrency features, and a robust standard library make it an excellent choice. The built-in net/http package provides powerful tools for handling HTTP requests and building web servers. Go’s easy-to-understand syntax and comprehensive documentation enable developers to quickly create reliable web applications regardless of scale. Whether you’re developing a small web application or a large-scale web service, Go offers a versatile and reliable language for web development on Ubuntu. Take advantage of Go’s strengths and enjoy a productive web development experience on Ubuntu.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Get UUID in Linux [5 Best Methods]

Next Post

How to Install Arch Linux on VirtualBox [17 Effective Steps]

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next