How to setup Ruby on Rails on RaspberryPi

2024-02-23
sudo apt install rbenv
sudo apt remove ruby-build
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
sudo apt-get -y install ruby-dev postgresql libpq-dev libcurl4-openssl-dev libssl-dev libyaml-dev
# may need more packages if you will use active_storage and some more extensions.
rbenv install 3.3.0
rbenv global 3.3.0
rbenv init # to see the install instruction.
gem update --system
gem install bundler pg rails -N
rails new rails-practice1 --minimal --database=postgresql
cd rails-practice1 && rails s

yay-youre-on-rails

Tip:

To access to PostgreSQL database, execute the command as postgres user(sudo su - postgres).

createuser username -d
psql postgres -c "alter user username password 'secret'"