Go, also known as Golang, is an open-source programming language renowned for its simplicity, efficiency, and scalability. It is designed to meet the demands of modern software development by combining the best aspects of compiled languages like C++ with the ease of scripting languages like Python. Its concurrency support, fast compilation, and standard library make it a preferred choice for developers building scalable applications, microservices, and containerized workloads. Its popularity is growing in dynamic niches like cloud-native and Web3 development for building decentralized apps (dApps) and blockchain systems. Learning how to set up and work with Go is becoming an essential skill for developers aiming to create efficient and reliable applications.
In this article, we’ll guide you through the step-by-step process of installing Go on Ubuntu 22.04. This guide will help you set up a clean and functional Go environment. By the end of this tutorial, you’ll be ready to write, compile, and run Go programs seamlessly on Ubuntu.
Prerequisites
- A Virtual Machine (such as the ones provided by NodeShift) with at least:
- 1 vCPUs
- 1 GB RAM
- 2 GB SSD
- Ubuntu 22.04 VM
Note: The prerequisites for this are highly variable across use cases. A high-end configuration could be used for a large-scale deployment.
Step-by-step process to install Go on Ubuntu VM
For this tutorial, we’ll use a CPU-powered Virtual Machine by NodeShift, which provides high-compute Virtual Machines at a very affordable cost on a scale that meets GDPR, SOC2, and ISO27001 requirements. It also offers an intuitive and user-friendly interface, making it easier for beginners to get started with Cloud deployments. However, feel free to use any cloud provider you choose and follow the same steps for the rest of the tutorial.
Step 1: Setting up a NodeShift Account
Visit app.nodeshift.com and create an account by filling in basic details, or continue signing up with your Google/GitHub account.
If you already have an account, login straight to your dashboard.
Step 2: Create a Compute Node (CPU Virtual Machine)
After accessing your account, you should see a dashboard (see image), now:
- Navigate to the menu on the left side.
- Click on the Compute Nodes option.
- Click on Start to start creating your very first compute node.
These Compute nodes are CPU-powered virtual machines by NodeShift. These nodes are highly customizable and let you control different environmental configurations, such as vCPUs, RAM, and storage, according to your needs.
Step 3: Select configuration for VM
- The first option you see is the Reliability dropdown. This option lets you choose the uptime guarantee level you seek for your VM (e.g., 99.9%).
- Next, select a geographical region from the Region dropdown where you want to launch your VM (e.g., United States).
- Most importantly, select the correct specifications for your VM according to your workload requirements by sliding the bars for each option.
Step 4: Choose VM Configuration and Image
- After selecting your required configuration options, you’ll see the available VMs in your region and as per (or very close to) your configuration. In our case, we’ll choose a ‘1 vCPUs/1GB/25GB SSD’ Compute node.
- Next, you’ll need to choose an image for your Virtual Machine. For the scope of this tutorial, we’ll select Ubuntu, as we will install Go on Ubuntu.
Step 5: Choose the Billing cycle and Authentication Method
- Two billing cycle options are available: Hourly, ideal for short-term usage, offering pay-as-you-go flexibility, and Monthly for long-term projects with a consistent usage rate and potentially lower cost.
- Next, you’ll need to select an authentication method. Two methods are available: Password and SSH Key. We recommend using SSH keys, as they are a more secure option. To create one, head over to our official documentation.
Step 6: Finalize Details and Create Deployment
Finally, you can also add a VPC (Virtual Private Cloud), which provides an isolated section to launch your cloud resources (Virtual machine, storage, etc.) in a secure, private environment. We’re keeping this option as the default for now, but feel free to create a VPC according to your needs.
Also, you can deploy multiple nodes at once using the Quantity option.
That’s it! You are now ready to deploy the node. Finalize the configuration summary; if it looks good, go ahead and click Create to deploy the node.
Step 7: Connect to active Compute Node using SSH
As soon as you create the node, it will be deployed in a few seconds or a minute. Once deployed, you will see a status Running in green, meaning that our Compute node is ready to use!
Once your node shows this status, follow the below steps to connect to the running VM via SSH:
- Open your terminal and run the below SSH command:
(replace root
with your username and paste the IP of your VM in place of ip
after copying it from the dashboard)
ssh root@ip
2. In some cases, your terminal may take your consent before connecting. Enter ‘yes’.
3. A prompt will request a password. Type the SSH password, and you should be connected.
Output:
Step 8: Install Go (two methods)
There are mainly two ways you can install Go. First is the standard method of installing through the Ubuntu package manager, and the other one is installing through go binary using the wget
command.
However, the first method does not guarantee the latest version of Go, which is why the second method is mostly preferred. Let’s dive into each method one by one:
a) Install Go using the Ubuntu package manager
- As usual, start by updating the Ubuntu package source-list to sync with the latest package versions and security patches.
sudo apt-get update
Output:
2. Next, install Go with the apt-get
command.
sudo apt-get -y install golang-go
Output:
3. Check the version.
go version
Output:
Observe that the current version installed through the first step is go1.18.1
. Since Go allows you to manage multiple versions of installation, we’ll go ahead and perform another installation through the binary file using the second method.
b) Install Go using binary file.
- Choose the latest binary file version.
Visit the official Go website to view all releases and select the latest version or any version you would like to install. Now, for instance, in the image below, the newest version mentioned is go1.23.4
, which clearly means that the installation done using the first step is not the latest.
Copy the link address of this mentioned version and download this binary file using the command below:
(you may provide a custom filename of the downloaded file by replacing the <CUSTOM_FILENAME>
with a filename. E.g., go.tar.gz
)
wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz -O <CUSTOM_FILENAME>
Output:
2. Extract the downloaded package.
sudo tar -xvzf go.tar.gz -C /usr/local
Output:
3. Check the version.
Finally, recheck the version to confirm if the version installed with this method is the latest.
go version
Output:
Step 9: Set the PATH variable.
Now, while working with Go, to ensure it is accessible from anywhere in the system, we’ll configure its path variable using the following command:
echo export PATH=$HOME/go/bin:/usr/local/go/bin:$PATH >> ~/.profile
Then, save the changes in the file.
source ~/.profile
Step 10: Test the installation
Once the setup is done, we’ll run a demo hello-world Go file to test if the installation went flawlessly and Go is working as expected.
- Create a file named
hello_world.go
in the working directory.
touch hello_world.go
2. Paste the below code snippet in the file.
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
It looks like this in the file:
3. Run the hello_world.go
file and see the output.
go run hello_world.go
Output
As you can see, we have successfully received the “Hello, World!” output from our code, which means Go is working perfectly fine.
Conclusion
Installing Go on Ubuntu 22.04 helps developers to quickly set up a robust environment for building high-performance applications. This guide covered each step, from downloading Go tarball with different methods to configuring the PATH for seamless usage and further testing the installation with a demo code, ensuring a smooth start for developers. If you’re using Go for containerized applications, with NodeShift, you can also simplify building and deploying your projects with its optimized workflows for Kubernetes and Terraform. By leveraging NodeShift’s developer-friendly cloud dashboard, developers can focus more on coding and less on configuration, making it a reliable companion for similar setups and beyond.