14 C
Texas
angeloma
Senior Writer and partner

How to install Go Language on FreeBSD 12?

Hi, friends in this post, you will learn how to install Go on FreeBSD 12. This popular programming language is gaining more and more followers every day.

Go is an open source (BSD license) programming language that was born with the objective of allowing the creation of efficient and easily distributable applications. So, it has binaries for Windows, Mac OS and of course, for Linux.

One of the main features of Go is the efficiency with which it manages computer resources. To the extent that many claims to be the natural replacement of C.

On the other hand, Go is a compiled language and has a garbage collector that tries to reduce the latency to the minimum guaranteeing optimal performance.

- Advertisement -

For this and many other reasons is that more and more developers have it as their main language.

Install Go language on FreeBSD 12

One of the main advantages of FreeBSD is that it has a large number of packages available from the official repositories. However, not all of them are up-to-date.

So in this post, we will download and install the latest stable version of Go which is 1.14.

First, open a terminal session. Once you have it open, you need to install curl to download Go.

:~$ sudo pkg install curl
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 2 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
	curl: 7.67.0
	ca_root_nss: 3.50
Number of packages to be installed: 2
The process will require 4 MiB more space.
1 MiB to be downloaded.
Proceed with this action? [y/N]: y

1.- Install curl on FreeBSD 12
1.- Install curl on FreeBSD 12

Once you have installed curl, we can start the download of Go with the following command:

:~$ curl https://dl.google.com/go/go1.14.freebsd-amd64.tar.gz --output go.tar.gz

2.- Download Go language on FreeBSD 12
2.- Download Go language on FreeBSD 12

When the download is finished we have to unzip it and move it to the /usr/local/ directory

:~$ tar xvf go.tar.gz
:~$ sudo mv go /usr/local

Go is ready for action, but it is convenient to make it available globally in our terminal. To do this, you have to edit the profile file.

:~$ sudo nano ~/.profile

And add the following content at the end:

export GOROOT=/usr/local/go 
export GOPATH=$HOME/work/
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

3.- Configuring go
3.- Configuring go

I’ll explain something quickly. The second line refers to a folder called “work” in that folder is where we have to include all our Go projects. Of course, you can replace the name “work” with whatever you want.

Save the changes and close the file.

Now you can see the version of Go installed with the following command:

:~$ go version
go version go1.14 freebsd/amd64

5.- Go 1.14 installed
5.- Go 1.14 installed

This indicates that Go is available from the console no matter where the prompt is located.

Testing Go

Now that Go is installed, let’s do the classic Hello World program to check that everything is okay.

First, we’ll create the project folders. Remember that it will be inside the work folder. Inside it, the project folder and inside it, the src folder where we will create the source file.

:~$ mkdir -p $HOME/work/src/hello

Then, create the source file and add the following content

:~$ nano ~/work/src/hello/hello.go
package main 
 import "fmt"
 func main() {
 fmt.Printf("hello, world\n")
 }

5.- Creating the hello world program in Go language
5.- Creating the hello world program in Go language

Finally, we build the project, compile the source code and execute it:

:~$ go build hello
:~$ go install hello
:~$ hello
hello, world

6.- Go language on FreeBSD 12
6.- Go language on FreeBSD 12

So, Go is ready to use.

Conclusion

There are many programming languages but there is always room for innovation and that is what Go gives us. An efficient language and with the support of a giant like Google.

Please share this post and join our Telegram channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article