Generally setting up a rails app is running some same set of commands, for example installing gem, creating database, loading schema and start rails server.

We can create a script and run it to setup our application since Rails 4.2 a bin/setup file is generated by default.

Here is the example of setup script.

Setup script sets your rails application for development environment instantly.  This is helpful when a new developer trying to set up your application or when setting up an application on a new machine. We should keep the setup script updated.

Let’s understand the setup script step by step and modify according to our requirements.

First setup basic required library and path of our application in APP_ROOT

Now system! method here execute the commands passed to it and shows the backtrace of error in case of command fails.

system will execute the given rails command and abort will stop script execution and will show us the backtrace of failed command, we can modify it if we don’t want to stop the execution of the script and get some custom error messages.

In the below snippet of the script, we are going to our application root and performing operations.

To create config file if not already exist, modify your script as