HomeLinuxThe right way to Set up Go Language on Ubuntu

The right way to Set up Go Language on Ubuntu


Google developed the Go programing language to create a language that’s as highly effective as C++ however follows easy syntax like Python.

And due to its effectivity, platforms equivalent to Docker, Kubernetes, and Terraform are written within the Go language.

If you’re writing code in Go or compiling a Go-based software, you could set up it first.

On this tutorial, I will present the next methods of putting in Go on Ubuntu:

  • Utilizing apt from Ubuntu repositories: Easiest possibility however not the newest model.
  • Utilizing snap: Easy and sometimes newer model.
  • Utilizing supply code: Advanced technique that offers you the newest model.

Let’s begin with the only and most really useful technique.

For those who do not care about having the latest model, it may be put in with the next command:

sudo apt set up golang

You may verify if it has been put in, utilizing the next command:

go model

Whereas writing, you get Go model 1.18.1 which is one level launch behind the latest model:

check the installed version of go programming language

Nice! So you might have checked that Go is put in in your Ubuntu system. However is it working accurately? Let’s verify that by working a easy Go program.

Run the Easy Go program

Right here, I’m going to create a easy Whats up world program to cross-check the set up.

I’m going to use nano to create and open the file named Hello_world.go:

nano Hello_world.go

And my file contents are the next (do not choose me, I am professional okay):

bundle primary

import "fmt"

func primary() {
        fmt.Printf("Fingers crossedn About to print Whats up world!n")
}
hello world program for Go programming language

Save the file contents and exit Nano by urgent Ctrl + X.

Now, you’ll have to append the run flag and filename to the command to run this system:

go run Hello_world.go
run go programs on linux

Operating as anticipated!

You might additionally construct an executable Go file like this:

go construct Hello_world.go

That was easy. You’ve Go language put in correctly. Let’s shortly see the removing steps.

Take away Go from Ubuntu

Because you put in it from Ubuntu’s repositories utilizing the apt command, the removing is fairly easy.

sudo apt take away golang

You may as well run the autoremove afterward.

sudo apt autoremove

Methodology 2:  Utilizing snap to put in a more recent model of Go

That is the best solution to get the latest model of any bundle as you do not have to undergo any complicated slightly than executing one command.

And Ubuntu comes pre-configured with snaps so why to not profit from this? Snap might be simply put in on different distributions as nicely.

The right way to Set up and Use Snap in Varied Linux Distributions

Snaps are Canonical’s means of offering a cross-distribution bundle administration system. On this article, we are going to see how one can set up and use snaps in numerous Linux distributions.

To put in the current model of Go together with snap, use the next command :

sudo snap set up go --classic
install the latest version of go language in Ubuntu using snaps

And as you possibly can see, it put in Go language model 1.19.5 which is the latest steady launch whereas writing.

Take away the snap Go

For those who not want Go language put in in your system or you might be simply not into utilizing snaps anymore and need to take away it, observe the given command:

sudo snap take away go

To crosscheck whether or not it’s eliminated efficiently, verify the put in model:

go model
check go version in ubuntu

And if you happen to get the identical error, Go has been eliminated efficiently.

🚧

That is probably the most sophisticated technique and I don’t advocate this. I included it for informational functions.

To construct Go from supply, go to its official obtain web page and select the bundle in your system accordingly.

visit official download page of Go programming language

Subsequent, extract the binaries to the /usr/native listing utilizing the tar command:

sudo tar -xzf go1.19.5.linux-amd64.tar.gz -C /usr/native/

Subsequent, you might be required to set the setting variable in order that system can work out the place to search for the Go executable.

So first open the /and many others/profile utilizing the next command:

sudo nano /and many others/profile

And press Alt + / to leap to the top of a line within the nano textual content editor and paste the next line:

export PATH=$PATH:/usr/native/go/bin
set environment variable for Go programming language in ubuntu

Now, save adjustments and exit from the nano textual content editor.

To take impact from the setting path you might have simply added, you’ll have to supply the file:

supply /and many others/profile

Go has efficiently been put in in your system. You may verify the put in model:

go model
source the etc profile file on linux

The right way to uninstall

Eradicating packages put in from the supply code is much more sophisticated. However you possibly can take away the Go out of your system by following three straightforward steps.

First, take away the Go binaries that you simply extracted whereas putting in:

sudo rm -rf /usr/native/go

Second, take away the setting path variable type /and many others/profile:

sudo nano /and many others/profile
remove go programming language when installed from source

And third, supply the file to use the adjustments:

supply /and many others/profile
Command 'go' not found on Ubuntu

On the lookout for an open-source IDE to run Go applications?

So that you realized to put in Go on Ubuntu Linux. You additionally ran a easy Go program. But when you need to write applications in Go, you will be higher off with a correct code editor.

I exploit VSCode for my every day coding duties however this cannot be the identical for you.

So we’ve got compiled an inventory of recent open-source IDEs on which you’ll run your Go applications effectively:

7 Finest Fashionable Open Supply Textual content Editors For Coding in Linux

On the lookout for the perfect textual content editors in Linux for coding? Right here’s an inventory of the perfect code editors for Linux. The perfect half is that each one of them are free and open-source software program. For those who ask skilled Linux customers, their solutions would most likely embody Vim, Emacs, Nano, and many others. No

And in case you are a VSCode person like me and searching for an alternate, you possibly can use the VSCodium 100% open-source model of Microsoft VSCode.

Please use the remark part for any queries associated to this information or options on what I ought to cowl subsequent.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments