What we are going to configure?
1) Ruby (rbenv).
2) Ruby On Rails.
Ruby on Rails is one of the most popular and fast application stacks for developers looking to create sites and web apps. The Ruby programming language, combined with the Rails development framework, makes app development simple.
Let’s start Installation and configuration of Ruby On Rails
Managing the multiple projects which are developed in different ruby versions, is a difficult task for a developer. To overcome the difficulty we use rbenv, which is a command-line tool. rbenv will provide you with a solid environment for developing your Ruby on Rails applications as it will let you easily switch Ruby versions. You can find it on Github. https://github.com/rbenv/rbenv Let’s install the dependencies *First of all, you have to update your ubuntu :
$sudo apt-get update
* Install the dependencies required for rbenv and Ruby for ubuntu :$sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
*Once you have done the above steps. Means you are ready to install rbenv.
* Let’s install rbenv :
Now you are ready to install rbenv . Let’s clone the rbenv repository from git. By using the below commands.
$cd && git clone https://github.com/rbenv/rbenv.git ~/.rbenv $echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc $echo 'eval "$(rbenv init -)"' >> ~/.bashrc $exec $SHELL $git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build $echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc $exec $SHELL
Now you are ready to install ruby.
* Let’s Install ruby :
Now you are able to install ruby. But before that, you have to know, which version you have to install and how many versions are available. So don’t worry, use the below command.
$rbenv install -l
The output of the above command is a long list of versions. Which is helps you to find, what you need? Once you select your version use below command.
$rbenv install 2.3.1 $rbenv global 2.3.1
For example, I am using ruby 2.3.1 that’s why I am using 2.3.1 If you need other versions like 2.3.0 you can use $rbenv install 2.3.0, etc.
*You have done your installation.
*check you did correctly or not.
Verify that Ruby was properly installed or not, check the current ruby version. $ruby -v Output: current version of ruby.
If the output version is the same as you select and use the above command. This means you did great. Okay, we complete one step Let’s move to next and install Rails.
*Let’s install and create a Rails environment.
You can install the most recent version of Rails with the gem install command.
$gem install rails OR if you would like to install the different versions. You can specify the version.
$gem install rails -v 5.1.5
After the installation checks the version.
Now we are ready to create a Rails application.
* Create a Rails Application :
Move to your working directory and then use the below command.
$rails new <application name >
Example : $rails new blogging
This command generates a new rails application with the default sqlite3 database if you would like to use other databases you use below command for generating rails application.
$rails new <application name > -d postgresql
$rails new <application name > -d mysql
I am using sqlite3 for this application.
After using the above command it creates a list of directories and files. Move to your application directory
$cd <name of your application >
Example: $cd blogging
Now you’re in your application directory. You have to install bundle first. $gem install bundle
Then $bundle install
once the bundle installation is finished. Let’s test the application is working or not use the below command to run the server.
Open your browser and type the below URL.http://localhost:3000
Let’s Create a new model controller and view for blogging.
$rails g scaffold Blog title:string body:text
This command generates a list of directories and files.
Use this command for migrate database
After that open the routes file.
<project locatio> $ vi config/routes.rb
You can open it in any text editor like sublime,gedit etc.
And add below line before resources :blogs
Then start your application using
Refresh your web page or open this URL http://localhost:3000
Yeeeeeeeeeee it’s working .. 🙂 .
Special Thanks to https://runwithcode.blogspot.com/2018/02/installation-and-configuration-of-ruby.html for the amazing articles.
Thanks for reading have a nice day.