How to setup new Dev machine for Ruby On Rails
Omakub for Ubuntu
https://omakub.org/ is great and after installing ubuntu on my machine, the first thing I do is install omakub, this setup Dev environment with different softwares, Docker, etc. Check https://omakub.org/ for more information.
LazyVim
https://www.lazyvim.org/ - This is really awesome IDE for neovim, if you are a vim user. Otherwise go with Vscode.
1. Install Ruby, nodejs and Postgresql
It uses mise, but you can use asdf. Because these tools helps you install different versions of ruby, node from single tools. If your system is already using different plugin manager for different tools e.g: rbenv for ruby and nvm for node, you are good as well.
Install Ruby, nodejs and Postgresql using https://gorails.com/setup/ubuntu/24.04
- make sure to install following versions:
ruby: 3.1.6
rails: 6.1.7.6
postgresql: latest (should work), upto version 15 is tested.
nodejs: 16.16.0 (use this exact version)
And also install `npm install -g yarn` because rails uses `yarn` package manager.
2. Install Elastic search
- If you are using docker, you can simply use:
docker start elesticsearch_7 || docker run -d --name elesticsearch_7 -p 9200:9200 -e \"http.host=0.0.0.0\" -e \"transport.host=127.0.0.1\" docker.elastic.co/elasticsearch/elasticsearch:7.10.1
And your elastic search should be setup for the project. Otherwise you can install elastic search in your system depending on OS e.g: brew install elasticsearch@7.10.1
or using apt get install ....
3. Install Redis
Install redis using https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/ for os of your choice
4. Imagemagick
ubuntu
sudo apt-get install imagemagick
macos
brew install imagemagick
5. Once all the dependencies are installed, You can clone the project and install required dev dependencies:
git clone git@github.com:<appname>.git
cd <my-app>
bundle install
6. Configure config variables and database configuration
copy config/database.yml and adjust the username and password if needed. If you followed https://gorails.com/setup/macos/15-sequoia postgresql installation, you should have created your system user in your database, which don't require you to enter password to access the DB. In anycase, change your host, username and password depending on how you installed postgresql (e.g: docker has different host).
cp config/database.sample.yml config/database.yml
copy config variables, or .env
files depending on your project’s requirement.
touch config/application.yml
And ask for credentials from DEV.
Final step
Once all the dependencies are installed and project is setup correctly, we can create database and generate database migration and start using application with:
NOTE: make sure to run
rails db:schema:load
If there are corrupted migrations in the project.
cd <my-app> # if not already
rails db:create
rails db:schema:load
rails db:migrate
rails db:seed
Run the project
run these scripts in different terminal tabs or windows:
rails app
bin/setup
rails server
sidekiq
bundle exec sidekiq
and visit http://localhost:3000
If everything is setup correctly, your app should work.
Setup stripe (if you are using them)
Because you can't access our app without trial payment, you need to run the stripe webhooks to add subscriptions, to setup stripe follow:
One time steps:
Install stripe cli: https://docs.stripe.com/stripe-cli
Login to stripe pex account. Ask for permission if needed.
stripe login
To listen to stripe webhooks
stripe listen --forward-to localhost:3000/pay/webhooks/stripe