Skip to content

Linux Dev Setup Guide

Zach Gollwitzer edited this page Aug 13, 2024 · 14 revisions

If running the project locally, follow these instructions to get started:

Note on Linux Distros

This guide is specifically for Ubuntu 22.04. If you are using another distro (other than Ubuntu) and cannot get the project started, please let us know in Discord so we can add instructions for it.

Install Ruby

Find the required Ruby version here.

First, update package repository and install dependencies:

sudo apt-get update

sudo apt-get 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

Now, install rbenv:

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Restart your shell for changes to take effect. Then, install a Ruby version:

rbenv install <required-ruby-version>

At this point, you may run into issues as the Debian and Ubuntu repositories do not keep an updated version of rbenv. To solve this, you can install ruby-build with the following command:

cd "$(rbenv root)"/plugins/ruby-build && git pull

If you run into issues, please see the troubleshooting guide below.

Once you have it working, install the Ruby version and set it as the default on your machine if desired:

rbenv install <required-ruby-version>
rbenv global <required-ruby-version>

Check your Ruby version:

ruby -v

If this still does not show the correct version, you may need to run the following commands to avoid conflicting binaries:

rbenv local --unset
rbenv shell --unset

Install PostgreSQL

Install Postgres and start it as a service:

sudo apt install postgresql libpq-dev

sudo service postgresql start

Install other dependencies

The app uses ActiveStorage, which requires some 3rd party libraries to be installed on your system. For the app to work properly, you'll need to install libvips:

sudo apt install libvips

Start the Project

Start by forking and then cloning the repo locally. Then run the following commands to start the app:

cd maybe
cp .env.example .env
bundle install
bin/rails db:setup
bin/dev

Troubleshooting

Postgres user authentication issues

Make sure you have a user setup:

sudo -i -u postgres
psql
\password postgres
<follow instructions to set password for 'postgres' user
exit
exit

And make sure to add the newly created user to .env:

# Database Configuration
DB_HOST=localhost
POSTGRES_PASSWORD=<new password>
POSTGRES_USER=postgres

rbenv doesn't show latest version of Ruby

I'm attempting to install version 3.3.0 of Ruby, but my terminal says version 3.3.0 is not available?

Run the following command to list the available versions of ruby that can be installed by the rbenv's ruby-build plugin.

rbenv install --list

If version '3.3.1' is not listed as one of the options within the displayed list, you may need to upgrade rbenv's ruby-build installation to gain access to Ruby Version 3.3.1. To update ruby-build, simply enter the following command:

cd "$(rbenv root)"/plugins/ruby-build && git pull

Run the --list command again to determine whether Ruby Version 3.3.0 can now be downloaded.

Cannot set default Ruby version

I've installed Ruby 3.3.1 via rbenv and set it as my default Ruby version. However, a different version of Ruby is still listed as my default?

If rbenv global 3.3.1 seems to run but doesn't change the Ruby version, your shell might be using a different ruby installation (such as one installed via apt). Confirm that you are using the rbenv managed version of ruby by running this command:

which ruby

When using rbenv, this command should usually list the home directory /root/.rbenv/shims/ruby as the location of your ruby installation. If the command lists the /usr/bin/ruby directory, or another separate directory, this likely means you are using an outside installation of ruby rather than the one managed by rbenv.

To remedy this, add the following lines to the end of your /root/.bashrc file:

export PATH="/root/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Save the file, reload your shell profile, and verify that you're using the rbenv managed ruby installation by running these commands:

source /root/.bashrc
echo $PATH
which ruby

If everything looks fine but the wrong version of Ruby is still installed, you may need to run the following commands to avoid conflicting binaries:

rbenv local --unset
rbenv shell --unset

Linux console cannot find or execute shell scripts

You'll probably need to set your Git config:

git config --global core.autocrlf false

Please see this explanation for more detail.