OT: (NOOB) Settings GOROOT and GOPATH on Freebsd

299 views
Skip to first unread message

Mauro Risonho de Paula Assumpção

unread,
Dec 22, 2013, 12:00:02 AM12/22/13
to golang-nuts

I'm trying to use and compile programs made in golang on freebsd 9.2 and 10.0 rc1, but I'm problems setting variables and GOROOT GOPATH environment.

I'm trying to use command:

export
setenv

But, unsuccessfully.

Has anyone managed to solve this?

@firebitsbr

Tamás Gulácsi

unread,
Dec 23, 2013, 8:18:28 AM12/23/13
to golan...@googlegroups.com
What is the error?
What says "go env" after you set those variables?

mrpa.a...@gmail.com

unread,
Aug 25, 2017, 4:35:21 PM8/25/17
to golang-nuts, mauro....@gmail.com


I found a solution that solved my problem, now using FreeBSD 11.1 x86_64

Nginx Reverse Proxy and Golang Setup on FreeBSD

Requirements

Basic knowledge of UNIX.
FreeBSD x64 with Nginx installed.
Install Tools

You will need several programs that are not shipped with FreeBSD. Run the following command to install them:

pkg install nano wget git mercurial bzr
Download and Install Golang

Download golang by running the following set of commands:

cd /tmp
tar -C /usr/local -xzf go1.3.3.freebsd-amd64.tar.gz
Setup Environment Variables

Create a variable called GOPATH (which will be the location for installed packages) and add it to your path:

mkdir ~/.gopkg
setenv GOPATH /root/.gopkg
set path = ($path /usr/local/go/bin /root/.gopkg/bin)
If you want to have the path set on boot, then run the following command to add it to your .cshrc:

echo "setenv GOPATH /root/.gopkg" >> ~/.cshrc
echo "set path = ($path /usr/local/go/bin /root/.gopkg/bin)" >> ~/.cshrc
Verify Installation

Run go in your terminal. If you are presented with a list of options, then the installation was successful. Run the following command to install a web framework called Martini:

If you don't see any errors, then you may proceed to the next step.

Setup Martini

Create a file called server.go and populate it with the following lines of code:

package main


func main() {
  m := martini.Classic()
  m.Get("/", func() string {
    return "Hello from Vultr VPS :)!"
  })
  m.Run()
}

When done, save and run go run server.go. Provided that you do not see any errors on your terminal, then you can proceed to the next step.

@firebitsbr
Reply all
Reply to author
Forward
0 new messages