GoCommerce is Netlify’s headless e-commerce for JAMstack sites. Whatever that means.

It acts as your database when you have a single page app (possibly in React) that sells stuff. Integrates through <script> tags with JSON in them.

I hear Netlify is working on a fully hosted solution. It’s not ready yet.

Digital Ocean droplets are a glorified VPS, virtual private server. I’m told it’s actually an IaaS (infrastructure as a service) and competes with Amazon’s AWS…

Sure felt a lot like ssh-ing into a VPS and mucking about. πŸ€·β€β™€οΈ

Recently, I had to make these two work together. I looked for a guide, but none could be found. So here’s a collection of my notes with some explanation.

The whole process takes about 10 minutes, if you know what you’re doing. Writing this will help me know what I’m doing next time πŸ™‚

Get a droplet, then set it up

I was given an existing droplet. This assumes you have a Digital Ocean Droplet running Ubuntu. Just the initial “Here’s your VPS” setup that comes out of the box.

πŸ‘‰ First step of this tutorial

Next we have to set up a user because running things as root is bad. I won’t go into why it’s bad right now because it’s just something I remember from my Linux-using days many years ago. It’s bad. Don’t do it.

πŸ‘‰ Follow this tutorial

The instructions boil down to:

  1. Login as root
  2. Create new user (I used gocommerce)
  3. Give it sudo privileges
  4. Add your personal public ssh key to the server’s authorized keys
  5. Login as new user

Login, install SQLite

Once you have a new user, it’s time to login and set up Gocommerce. This involves installing golang, sqlite3, and a few knickknacks.

Login to your server. My user was called gocommerce.

$ ssh gocommerce@<YOUR_IP>

Then install sqlite3. SQLite is a simple database that’s easy to setup. If you want to use this for real production, I suggest opting for Postgres.

πŸ‘‰ Following this Quora answer

$ sudo apt-get update
$ sudo apt-get install sqlite3 sqlite3-dev

apt is Ubuntu’s package management system. Much like npm for JavaScript. update updates the local listing of software packages, install installs them. I used to know why this was apt-get and not just apt.

I also used to know why you need to install sqlite3-dev, but I have since forgotten. Doesn’t matter.

You now have SQLite and can create local database. Single file, SQL interface. Wonderful.

Install Go

Installing Golang is a little harder. You can’t use the default package because Gocommerce needs at least Go version 1.7.

As I painfully discovered, the official version in Ubuntu packages is 1.6, and that’s not good enough.

πŸ‘‰ Followed this guide to install

πŸ‘‰ And this guide to configure

Here’s what it boils down to.

You install Go with these apt-get incantations.

$ sudo add-apt-repository ppa:gophers/archive
$ sudo apt-get update
$ sudo apt-get install golang-1.9-go

I installed the incorrect version of Go at first, so I also had to overwrite its executable with a link to the new one. You might not have to do this, and it’s probably a bad way of doing it, but πŸ‘‡

$ cd /usr/bin
$ sudo rm go
$ sudo ln -s /usr/lib/go-1.9/bin/go

When you run go version it should say 1.9.

Then we get to create $GOPATH and set it up in our .bashrc.

$ vim ~/.bashrc

Add these lines at the end of that file:

export GOPATH="$HOME/go"
export GOBIN="$GOPATH/bin"
export PATH="$GOBIN:$PATH"
export PATH="$PATH:/usr/local/go/bin"

This creates your $GOPATH and $GOBIN variables then adds them to $PATH. Go needs these to be able to execute stuff and load itself up.

Next you have to create that directory β†’

$ mkdir -p ~/go/src

This puts a directory called go in your home dir and a src dir inside that. ~/go/src is where all your Go code is going to live.

Build, configure, and run Gocommerce

Now that you have Go running, it’s time to set up Gocommerce.

First, create the directory it’s going to live in.

$ mkdir ~/go/src/github.com/netlify

Next go there and clone the repo from Github. Ubuntu comes with git preinstalled, so there’s no need to worry about that.

$ cd ~/go/src/github.com/netlify
$ make deps
$ make build_linux

make deps installs Go dependencies that Gocommerce uses and make build_linux builds Gocommerce itself. You have to build it for Linux because we’re running Ubuntu.

On your dev machine, if it’s a Mac, you’d use make build to compile for a Mac. You can see what Netlify considers the default πŸ™‚


To configure Gocommerce, you edit a .env file in its dir, ~/go/src/github.com/netlify/gocommerce/.env

You can see details in Gocommerce README. Something like this πŸ‘‡


The tricky one to find was that GOCOMMERCE_DB_AUTOMIGRATE. That keeps your database schema up to date.

You’ll need Stripe (or Paypal) and some sort of SMTP service. I’m using sendgrid here.


You can run Gocommerce using ./gocommerce. This runs the service directly, and you can check that it’s running at http://<your ip>:9111.

But it’s going to stop running once your ssh session times out. Not good.

We have to turn gocommerce into a Daemon, a script that runs in the background.

πŸ‘‰ Follow this guide for creating a custom systemd service

systemd is the system that Ubuntu uses to manage automatically starting scripts.

To do this, you create /etc/systemd/system/gocommerce.service. I used vim, so sudo vim /etc/systemd/system/gocommerce.service.

Description=Gocommerce Service



This assumes the user you created earlier is called gocommerce and that you haven’t moved the gocommerce executable.

You can now start the service.

$ systemctl start gocommerce

You should see a 404 error page on http://<your ip>:9111. That means gocommerce is running and serving request.


You can now close your ssh connection and gocommerce should keep running in the background forever.


Learned something new? Want to become a better engineer? πŸ’Œ

Join 9,400+ people just like you already improving their skills.

Here's how it works πŸ‘‡

Leave your email and I'll send you an Interactive Modern JavaScript Cheatsheet πŸ“– right away. After that you'll get a thoughtfully written email every week aboutΒ React, JavaScript,Β  andΒ lessons learned in my 20 years of writing code for companies ranging from tiny startups to Fortune5 behemoths.

Man, I love your way of writing these newsletters. Often very relatable and funny perspectives about the mundane struggles of a dev. Lightens up my day. ~ Kostas

PS: You should also follow me on twitter πŸ‘‰ here.
It's where I go to shoot the shit about programming.