# How to setup new Dev machine for Ruby On Rails

## Omakub for Ubuntu

[https://omakub.org/](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/](https://omakub.org/) for more information.

## LazyVim

[https://www.lazyvim.org/](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](https://github.com/jdx/mise), but you can use [asdf](https://github.com/asdf-vm/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](https://github.com/rbenv/rbenv) for ruby and [nvm](https://github.com/nvm-sh/nvm) for node, you are good as well.

Install Ruby, nodejs and Postgresql using [https://gorails.com/setup/ubuntu/24.04](https://gorails.com/setup/ubuntu/24.04)

* make sure to install following versions:
    

```sh
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:
    

```sh
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/](https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/) for os of your choice

## 4\. Imagemagick

**ubuntu**

```sh
sudo apt-get install imagemagick
```

**macos**

```sh
brew install imagemagick
```

## 5\. Once all the dependencies are installed, You can clone the project and install required dev dependencies:

```sh
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](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).

```sh
cp config/database.sample.yml config/database.yml
```

**copy config variables, or** `.env` files depending on your project’s requirement.

```sh
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.

```sh
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**

```sh
bin/setup
rails server
```

**sidekiq**

```sh
bundle exec sidekiq
```

and visit [http://localhost:3000](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](https://docs.stripe.com/stripe-cli)
    
* Login to stripe pex account. Ask for permission if needed.
    

```sh
stripe login
```

**To listen to stripe webhooks**

```sh
stripe listen --forward-to localhost:3000/pay/webhooks/stripe
```

### Ultrahook or Ngrok as a Dev webhooks listeners

* [https://www.ultrahook.com/](https://www.ultrahook.com/)
    
* [https://ngrok.com/](https://ngrok.com/)
