Skip to content

Getting Started on Linux

PelicanQ edited this page Apr 9, 2022 · 14 revisions

We highly recommend using a distribution of Linux or at least a UNIX-based system when working with the website. This way installation is (somewhat) easy and all the gem versions match the overall development environment of the website. If you have a computer running windows it's either recommended to dual boot (preferred) or run Linux on a virtual machine like VirtualBox.

These instructions assume you're running Linux and that you have Git installed.

Installing the prerequisites

The environment requires Ruby 2.5.0, a recent version of Postgres and Redis.

Installing Ruby

When installing Ruby it's easiest to first install rbenv and ruby-build. Start by checking that you have the required dependencies for your system.

Then run

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

and then install Ruby:

rbenv install 2.5.0
rbenv global 2.5.0

After this, you should restart your terminal emulator.

Installing Postgres

To install Postgres on a recent version of Ubuntu, it should be enough to run:

sudo apt-get install postgresql postgresql-contrib libpq-dev

If you are using the LTS (Long Term Support) version, you need to run the following commands instead:

sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev

On most other distributions, it's enough to install the postgresql or postgres package. For example, on Arch:

sudo pacman -S postgresql

Now, to start postgres:

sudo systemctl start postgresql

We probably want to make sure postgres starts on startup, like this:

sudo systemctl enable postgesql

To use Postgres with Rails you need to create a user:

sudo -u postgres createuser <username> -sP

Postgres will then ask you to set a password for the new user.

Installing Redis

Redis can usually be installed with your distribution´s package manager. It's often called either redis-server or just redis. On Ubuntu just run this command:

sudo apt-get install redis-server

On Arch, you just run

sudo pacman -S redis

Installing ImageMagick

When image files are uploaded from the client's browser to the server they are put in a temporary cache in /public/uploads/tmp. Then they can be processed, resized, watermarked and put in permanent storage in /public/uploads/{model-name} (/public/uploads/albums for instance). Original image is also saved in /public/storage. When viewing images on the website they are fetched from these permanent storage locations, not the temporary. For images to be processed, so they can later be viewed, ImageMagick must be installed:

sudo apt-get install imagemagick

Setting up Git

You need to configure Git if you have not used it before. Run

git config --global user.name "Firstname Lastname"
git config --global user.email name@domain.com

using the same email as on GitHub.

You are recommended to run the following command to simplify pushes to git.

git config --global push.default current

Installing this environment

To install the environment you should first clone the repo. Head to your preferred directory and clone. Afterwards you need to install Rails and all the gems required. All these things can be achieved by running the following commands:

cd <preferred folder>
git clone https://github.com/fsek/web.git
cd web

gem install bundle
bundle install

To run Rails and store data you need to configure the database connection. In the environment root folder there is a file called .env-sample. Copy this file and rename it to .env:

cp .env-sample .env

Now open the file in your favourite text editor and enter the username and password you chose when creating a Postgres user. Enter the same username and password for both the test and dev environment.

Before you can continue, Rails wants you to generate a "Secret key base". Run

echo "SECRET_KEY_BASE=$(rails secret)" >> .env

You are now ready to load the database structure into Postgres, and populate it with some example data. Run the following commands:

rails db:create && rails db:migrate && rails db:seed && rails db:populate_test

Running the server

To run the server and all the required services simply run the command:

foreman s

After a few seconds, you should be able to access the server at http://localhost:3000.