Skip to content

Development Environment Setup: Ubuntu

AdamOFN edited this page Jan 18, 2023 · 59 revisions

Intro

This guide will help you set up a development environment for OFN on Ubuntu 22.04 LTS or Ubuntu 20.04 LTS.

Step 1. Install Ruby, Node.js, Yarn, and rbenv

This section is based on instructions here (22.04) and here (20.04). Those instructions include a section on configuring git. That is optional, but may be useful to you. Rails does not need to be installed now. It is installed by a setup script in a later step.

The version of Ruby used in OFN is shown here. At the time of writing it is 3.0.3. If it has changed, the commands below starting with rbenv will need to be adjusted (and this guide updated).

sudo apt install curl
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
   
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
   
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
   
rbenv install 3.0.3
rbenv global 3.0.3
gem install bundler
rbenv rehash

Step 2. Install PostgreSQL and Redis

This will install PostgreSQL, the database that OFN uses, and Redis, which is used for caching. It also installs a supporting library for PostgreSQL.

sudo apt install postgresql redis-server libpq-dev

Step 3. Clone the OFN codebase and set it up

As per the Getting Started document, fork the OFN repo then enter the following to clone it and set up the database superuser.

cd
git clone https://github.com/YOUR_GITHUB_USERNAME_HERE/openfoodnetwork
cd openfoodnetwork
git remote add upstream https://github.com/openfoodfoundation/openfoodnetwork
git fetch upstream master
sudo -u postgres psql -c "CREATE USER ofn WITH SUPERUSER CREATEDB PASSWORD 'f00d'"

Step 4. Run the setup script and final steps

The next step is to run the setup script. This currently gives some error messages about missing dependencies, however these do not prevent you starting the dev server. If they bother you, you can avoid them with:

yarn add @babel/core
yarn add @hotwired/stimulus
yarn add @babel/plugin-transform-runtime

Then run the setup script

script/setup

This does not install foreman, which is used to start the dev server. Install it with

gem install foreman

Node.js needs an option to be set to tell it to use an older SSL provider, otherwise foreman start will throw a load of errors and then exit.

echo 'export NODE_OPTIONS=--openssl-legacy-provider' >> ~/.bashrc
exec $SHELL

Exit your shell and reopen it for the setting to take effect. You can then run the dev server with

foreman start

Step 5. Install Chromium and driver

Chrome or Chromium is used for UI testing. This is automated using a driver. Install them with

sudo apt install -y chromium-browser
sudo apt install -y chromium-chromedriver
Clone this wiki locally