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:
we will scroll down to where it says FreeBSD. At this time, we're at 1.14.2
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
And we are going to use wget to download go.
wget https://dl.google.com/go/go1.14.2.freebsd-amd64.tar.gz
This downloads the archive to our system. Let's unzip it.
tar xvf go1.14.2.freebsd-amd64.tar.gz
Now that it's unzipped we can verify the files extracted.
Let's move it to our local folder
sudo mv go /usr/local
Now let's open up our profile
sudo vim ~/.profile
In that file we want to add the following:
Wat we're doing here is setting our go root to /usr/local/go:
export GOROOT=/usr/local/go
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
Then we're putting the go path and go root into our main path.
export PATH=$GOPATH/bin:$GOROOT/bin:$path
Then we'll save that file.
Now let's verify our installation.
go version
As you can see, we have go version 1.14.2 installed.
Then we'll type in
go env
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
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)
}
And after saving and running the file:
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)
Btw brew is now available for linux, go can be installed using :
brew install go