Setup Go, Goby and PostgreSQL on a Linux system

Saverio Miroddi edited this page Nov 17, 2017 · 1 revision

These are the steps required in order to setup Go (1.9), Goby and PostgreSQL on a Linux system.

Install go from source (in /usr/lib)

$ wget -O /tmp/golang-1.9.tar.gz
$ sudo tar xv -C /usr/lib -f /tmp/golang-1.9.tar.gz
$ sudo mv /usr/lib/go /usr/lib/go-1.9

Set the paths

The most generic solution is to use $HOME/.bashrc.

Setting $GOPATH (the path of the Go workspace) to $HOME/go is a common setup:

$ echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc
$ echo 'export GOBY_ROOT=$GOPATH/src/' >> $HOME/.bashrc

Add the go workspace binaries to the path:

$ echo 'export PATH=$PATH:$GOPATH/bin' >> $HOME/.bashrc

Note that if your terminal is set to run as login shell, then you'll need to modify $HOME/.bash_profile instead.

Optionally add a shell function for selecting the Go version

$ cat <<<'STR' >> $HOME/.bashrc
# Switch go version; assumes that go versions are installed as `/usr/lib/go-1.X`
function goswitch {
  if [[ "$#" != 1 ]] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
    echo 'Usage: goswitch <version>'
    export PATH=$(perl -pe 's/:\/usr\/lib\/go-\d\.\d+\/bin//' <<< $PATH)
    export PATH=$PATH:/usr/lib/go-$1/bin

# Select go
goswitch 1.9

doing so will automatically select Go 1.9 on terminal invocation.

Reload the shell configuration, and download the repository:

$ source ~/.bashrc
$ go get

This will create the workspace directory ($GOPATH), if it's not present.

Install PostgreSQL

Install the provided package, on Ubuntu 16.04:

$ sudo apt install postgresql-9.5 postgresql-contrib-9.5

Trust clients connecting from the local machine:

$ sudo perl -i -pe 's/^((local|host).*)\b(\w+)$/$1trust/' /etc/postgresql/9.5/main/pg_hba.conf

Restart the service:

$ sudo systemctl restart postgresql

And create the test database:

$ psql -c 'create database goby_test;' -U postgres

Alternative PostgreSQL versions

PostgreSQL maintains a PPA with more recent PGSQL versions. In order to add it, execute:

$ wget -O - | sudo apt-key add -
$ echo "deb $RELEASE-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
$ sudo apt update

Then follow the instructions in the previous section, changing 9.5 with the desired version.

Happy hacking!

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.