So if you want to develop Go in FreeBSD, you can definitely use pkg to automatically install binaries. But I like to do it manually. My reasons are simple, I want to get the latest and greatest version of Go once it’s released, and I like to get manual control over the versions, even installing multiple versions sometimes.
Here’s how I do it on FreeBSD. (You can too Watch the video)
So let’s go to Golang’s download page first:
We scroll down to where FreeBSD is written. At this point, we are in 1.14.2
We will right-click and copy the link address.
Now we want to create a source directory. This can be any library you want.
And we’re going to use wget to download Go.
wget https://dl.google.com/go/go1.14.2.freebsd-amd64.tar.gz
It downloads the archive to our system. Let’s unload it.
tar xvf go1.14.2.freebsd-amd64.tar.gz
Now that it has opened, we can verify the extracted files.
Let’s move it to our local folder.
Now let’s open our profile.
In this file, we want to add the following:
What we are doing here is setting our go root to / usr / local / go:
export GOROOT=/usr/local/go
So we set our gopath to be in the “goprojects” directory in my home folder. You can call it whatever you want.
export GOPATH=$HOME/goprojects
So we put on the gopath and get into our main path.
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
So we’ll save this file.
Now let’s verify our installation.
As you can see, we have version 1.14.2 of go installed.
Then we type
This will show us the information of our go environment.
Let’s make a quick peace world to verify our installation.
I will create a new file called test.go
And I will enter the following code (which is a glorious world of peace)
package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Println("Hello from", runtime.GOOS)
}
And after saving and running the file:
there it is. Hello freebsd!
So this is how you install Go on FreeBSD. It’s that easy! You can update as often as you like and even run multiple versions at the same time.
If you want to learn more about Go or FreeBSD, sign up for my tutorial updates below!
Learn how to leverage a standard library like PRO. I just created a new course, Go Standard Librarycheck this out!