Install Golang on Ubuntu 22.04 with Easy Steps

Author

Reads 413

A Close-Up Shot of a Person in a Black Hoodie Holding Boxes while Using a Terminal
Credit: pexels.com, A Close-Up Shot of a Person in a Black Hoodie Holding Boxes while Using a Terminal

Installing Golang on Ubuntu 22.04 is a straightforward process that can be completed in a few easy steps.

First, update the package index by running the command `sudo apt update`. This ensures that the package list is up-to-date.

Next, install the necessary dependencies by running `sudo apt install -y curl`. This command downloads and installs the curl package.

Then, download the Golang installer from the official Golang website using `curl -O https://golang.org/dl/go1.19.linux-amd64.tar.gz`.

Installation Steps

To install Go on Ubuntu, the easiest way is to use the apt-get command: sudo apt-get update && sudo apt-get -y install golang-go.

You can test your fresh installation by running the command go version.

Go allows you to manage multiple installed versions, for example, to install version 1.17, use the command: go install golang.org/dl/go1.17@latest.

This command downloads the binary go1.17 in the folder ~/go/bin.

You can update your path environment variable if you want to use this version by adding the path to the profile file using the command: export PATH=/home/ubuntu/sdk/go1.17/bin:$PATH.

For your interest: Golang Version Manager

Credit: youtube.com, Install GO in Linux 2024 || Simple Steps

There are other ways to install Go on Ubuntu, but the most straightforward method is using the sudo apt install command.

However, this does not guarantee the latest version of Go will be installed.

To install Go using the wget command, go to the official Go website and select the correct Linux binary package version.

Copy the link address and run the wget command to download the file, you can specify a custom file name.

After the download, you need to extract the file using the command: tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz.

This will take some time to extract the files.

The go executable files are now located at /usr/local/go/bin/go.

Preparation and Verification

To verify your Golang installation on Ubuntu, you can run the command `go version`, which will print out the Go version. This is a straightforward way to confirm that Go is installed correctly.

The Go version will typically look something like this: `go1.21.1 linux/amd64`. The `go1.21.1` part shows the installed version of Go, and `linux/amd64` indicates the operating system and the architecture for which Go is installed.

Discover more: Go vs Golang

Credit: youtube.com, Golang installation on Ubuntu for beginners

To create a classic "hello world" program, you'll need to create a workspace. By default, Go uses the variable GOPATH that specifies the workspace location, set to `$HOME/go`. You can create the workspace by running `mkdir -v ~/go` and then `mkdir -pv ~/go/src/hello`.

Here are the basic steps to create a "hello world" program in Go:

Update Packages and Repositories

Before you start installing Go on your Ubuntu machine, take a moment to update the existing packages and repositories. This ensures you have the latest versions of the packages.

You can open the terminal on your Ubuntu machine and use the sudo apt update command to fetch the most recent updates. This command is crucial to keep your system up-to-date.

Next, execute the following command to upgrade your system's installed packages. You can also combine both commands and run them simultaneously, making the process more efficient.

Verify Installation

To verify the installation of Go, you can run the command `go version` in your terminal. This will print out the Go version that is installed on your system.

A Security Camera Installed On The Outside Wall
Credit: pexels.com, A Security Camera Installed On The Outside Wall

The output will show the version number, such as `go1.21.1`, and the operating system and architecture, like `linux/amd64`.

To further verify the installation, you can create a simple "hello world" program. This involves creating a workspace by setting the GOPATH variable to the location `$HOME/go`. You can do this by running the command `mkdir -v ~/go` and then `mkdir -p -v ~/go/src/hello`.

Next, you'll need to create a new file called `hello.go` in the `hello` directory using a text editor like `vim`. In this file, you'll add the code `package main import "fmt" func main() { fmt.Println("Hello, World!") }`.

Finally, navigate to the workspace directory and run the program using the command `go run hello.go`. If everything is installed correctly, you should see the output "Hello, World!" in your terminal.

Here are the basic steps to verify your Go installation:

  • Run `go version` to check the installed version
  • Create a workspace with `mkdir -v ~/go` and `mkdir -p -v ~/go/src/hello`
  • Create a new file `hello.go` with the "hello world" code
  • Run the program with `go run hello.go`

Ubuntu Specifics

To install Go on Ubuntu, you can use the package manager. This is the most straightforward method, but it may not guarantee the latest version of Go will be installed.

You might like: Golang Go

Credit: youtube.com, Install Golang in Linux | Ubuntu using terminal | Ubuntu 20.04LTS

You can install Go using the Ubuntu package manager with the command `sudo apt install golang-go`. Alternatively, you can install Go using Snapcraft, which is a universal Linux package that can function on any Linux distro.

The package manager installation method is simple and easy to use, but it's worth noting that it will automatically keep the package up-to-date. If you need to uninstall Go, it's easier to do so with this method.

There are two types of Go available on Ubuntu: `golang-go` and `gccgo-go`. The `gccgo-go` is the GCC implementation of the Go language, while `golang-go` is the original implementation by Google. You can install either one using the package manager or Snapcraft.

Configure on Ubuntu 22.04

To configure Go on Ubuntu 22.04, you should update the packages and repositories first. This can be done by opening the terminal and using the sudo apt update command to fetch the most recent updates.

If this caught your attention, see: Golang Mod Update

Credit: youtube.com, Ubuntu 22.04 LTS Rocks! // Beginners Guide Tutorial

The installation of Go on Ubuntu is relatively straightforward. The easiest way to do it is to use the apt-get command: sudo apt-get update && sudo apt-get -y install golang-go. This will install the latest version of Go available in the Ubuntu repositories.

You can test your fresh installation by running the go version command. This will print out the Go version, confirming that the installation was successful.

To manage multiple installed versions of Go, you can use the go install command followed by the version number. For example, to install version 1.17, you would run go install golang.org/dl/go1.17@latest.

Here's a summary of the steps to configure Go on Ubuntu 22.04:

After verifying the installation, you can configure the PATH environment variable to include the Go binary path. This can be done by running the export PATH=$PATH:/usr/local/go/bin command. Alternatively, you can update the PATH variable in the ~/.profile or /etc/profile file.

Getting Started

Credit: youtube.com, How to Use Ubuntu (Beginners Guide)

To start with Ubuntu, you need to install GO, which can be done easily.

First, create a workspace directory called go, just like we did in the example.

Next, navigate to the directory and create a new directory called src/hello.

Inside the src/hello directory, create a hello.go file where you can write your first Go program.

To run the program, use the command that was mentioned in the example.

Uninstallation

Uninstallation is a straightforward process if you know the right steps. If you used the apt-get command to install Go on your Ubuntu 22.04 machine, you can simply use the command to uninstall it.

To remove the files extracted in the go repository, you'll need to delete them manually. This is because the wget command doesn't automatically remove the files after installation.

You'll also need to remove the declared PATH variables in your profile to complete the uninstallation process. This will ensure that Go is completely removed from your system.

Recommended read: Golang Test Command

Getting Started

Credit: youtube.com, Install GO in Linux 2024 || Simple Steps

After installing Go on your Ubuntu system, it's time to get started with writing your first Go program. You'll need to create a workspace directory called "go" and navigate to it in the terminal.

Create a new directory called "src/hello" inside the workspace. You can do this by running the command "mkdir -p src/hello" in the terminal.

Now, navigate to the "src/hello" directory by running the command "cd src/hello". You should see a blank directory with no files inside.

To write your first Go program, create a new file called "hello.go" in the "src/hello" directory. You can do this by running the command "touch hello.go" in the terminal.

Testing and Validation

To run the code, save the file and type the command go run helloworld.go. This will print "Hello World." to the console, indicating that your Go installation is working correctly.

Verifying your Go installation is a crucial step to ensure everything is set up properly. Run the command go version to print out the Go version. This will give you a clear indication of the version of Go installed on your system.

Explore further: Install Print Studio Pro

Credit: youtube.com, How To Fix It The Golang installation error in the Ubuntu linux

To create the classic "Hello World" program, you'll need to create a workspace. Go uses the variable GOPATH to specify the workspace location, which defaults to the location $HOME/go. Create the workspace by running the command mkdir -v ~/go.

Next, create the directory ~/go/src/hello and navigate to it. Run the command vim ~/go/src/hello/hello.go to open a new file. Add the following code to the file:

package main

import "fmt"

func main() {

fmt.Println("Hello World.")

}

Finally, navigate to the workspace directory and run the program with the command go run hello.go. This will print "Hello World." to the console, indicating that your Go installation is working correctly.

Melba Kovacek

Writer

Melba Kovacek is a seasoned writer with a passion for shedding light on the complexities of modern technology. Her writing career spans a diverse range of topics, with a focus on exploring the intricacies of cloud services and their impact on users. With a keen eye for detail and a knack for simplifying complex concepts, Melba has established herself as a trusted voice in the tech journalism community.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.