DEV Community

Play Button Pause Button
Jeremy Morgan
Jeremy Morgan

Posted on • Originally published at jeremymorgan.com

How to install Golang in FreeBSD in 5 minutes

So if you want to develop Go in FreeBSD, you can certainly use pkg to automatically install binaries. But I like to do it manually. My reasons are simple, I like to have the latest and greatest version of Go the instant it's released, and I like to have manual control over the versions, even install multiple versions sometimes.

Here's how I do it on FreeBSD.

So let's first go to the Golang download page:

https://golang.org/dl/

we will scroll down to where it says FreeBSD. At this time, we're at 1.14.2

How to Install Go in FreeBSD

We'll right-click and copy that link address

Now we want to make a source directory. This can be any directory you want.

mkdir ~/src
cd ~/src
Enter fullscreen mode Exit fullscreen mode

And we are going to use wget to download go.

wget https://dl.google.com/go/go1.14.2.freebsd-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

This downloads the archive to our system. Let's unzip it.

tar xvf go1.14.2.freebsd-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

Now that it's unzipped we can verify the files extracted.

How to Install Go in FreeBSD

Let's move it to our local folder

sudo mv go /usr/local
Enter fullscreen mode Exit fullscreen mode

Now let's open up our profile

sudo vim ~/.profile
Enter fullscreen mode Exit fullscreen mode

In that file we want to add the following:

How to Install Go in FreeBSD

Wat we're doing here is setting our go root to /usr/local/go:

export GOROOT=/usr/local/go
Enter fullscreen mode Exit fullscreen mode

Then we're setting our gopath to be in the "goprojects" directory in my home folder. This can be named anything you want.

export GOPATH=$HOME/goprojects
Enter fullscreen mode Exit fullscreen mode

Then we're putting the go path and go root into our main path.

export PATH=$GOPATH/bin:$GOROOT/bin:$path
Enter fullscreen mode Exit fullscreen mode

Then we'll save that file.

Now let's verify our installation.

go version
Enter fullscreen mode Exit fullscreen mode

How to Install Go in FreeBSD

As you can see, we have go version 1.14.2 installed.

Then we'll type in

go env
Enter fullscreen mode Exit fullscreen mode

How to Install Go in FreeBSD

This will show us our go environment information.

Let's do a quick hello world to verify our installation.

I'll create a new file named test.go

vim test.go
Enter fullscreen mode Exit fullscreen mode

And I'll put in the following code (which is a fancy hello world)

package main

import (
    "fmt"
    "runtime"
)

func main() {
    fmt.Println("Hello from", runtime.GOOS)
}
Enter fullscreen mode Exit fullscreen mode

And after saving and running the file:

How to Install Go in FreeBSD

There it is. Hello freebsd!

So this is how you install Go in FreeBSD. It's that easy! You can update as frequently as you like and even run multiple versions in parallel.

If you want to learn more about Go or FreeBSD, follow me here on Dev.To!!

Top comments (1)

Collapse
 
padakipavan profile image
padaki-pavan • Edited

Btw brew is now available for linux, go can be installed using :
brew install go