Search This Blog

Tuesday, September 19, 2017

How to Install Ruby On Rails On Ubuntu | How To create Ruby on Rails Developing Environment On Ubuntu | ROR On Ubuntu.


How to create Ruby on Rails developing environment on Ubuntu step by step.




Ruby on Rails is a very popular platform for developing applications. It has some good security features and fast processing capabilities.

Ruby is a programming language works on Rails framework. You can easily install Ruby and Rails with the command-line tool rbenv.


Let's Start....!

Update Packages and Install Dependencies.

  • First of all update all the packages and install dependencies with following command.
$ sudo apt-get update

The apt-get command will ensure that the local package and cache updated.

  • Now install dependencies required for rbenv and Ruby with following command.
$ sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev

  • Now Install rbenv with clone ebenv repository from git as below.
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv


  • Do add following path so that you can use rbenv's command's

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc


  • Next, source rbenv by typing.

$ source ~/.bashrc


  • Now you can rbenv installed properly with typing following command.

$ type rbenv

The output will show as below.

rbenv is a function
rbenv () 
    local command;
    command="$1";
    if [ "$#" -gt 0 ]; then
        shift;
    fi;
    case "$command" in 
        rehash | shell)
            eval "$(rbenv "sh-$command" "$@")"
        ;;
        *)
            command rbenv "$command" "$@"
        ;;
    esac
}


  • In order to use the rbenv install command, which simplifies the installation process for new versions of Ruby, you should install ruby-build, which we will install as a plugin for rbenv through git.



$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

Ruby-build plugin rbenv is installed now and you can installed the ruby version, whatever you want.


  • You can use below command to check all the versions.



$ rbenv install -l


  • Now choose whatever version you want to install as below.



$ rbenv install 2.3.1


  • This command will install the ruby version and if you want to make default of this ruby version for all you can use the below command.



$ rbenv global 2.3.1


  • Use below command to check and verify that ruby successfully installed in your computer.



$ ruby -v

The output will show as below.

ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]


  • You will also want to install the bundler gem, to manage your application dependencies. use below command for the same.



$ gem install bundler

Now Install Rails

Rails is very easy to install with gem command. Gem are those packages that extend the functionality of Ruby.


  • Use below command to installed Rails.



$ gem install rails.


  • This command will install the latest version of rails but if you want to install the any specific version of Rails you can use below command.



$ gem install rails -v 4.2.7


  • Or if you want to search all the version for rails available, you can use below command.



$ gem search '^rails$' --all



  • Verify that Rails installed or not properly with below command.



$ rails -v



Install Database

  • If you need a database for your application and you want to install a MySQL database you can install it easily with apt-get command.

$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev

  • and mysql2 gem can be installed with below command.

$ gem instal mysql2

  • Now you can use the database with your application but make sure you have configured the connection credentials in your application.

Create a Test Application.

When you have ensured that the ruby and rails have been installed properly you can create a ruby application as below with simple steps.

  • Go inside the directory where you want to create the project with "cd" command

$ cd ~

  • Now create a Rails application with below command easily.

$ rails new test app

  • Go inside the test app

$ cd test app

  • Create sqlite3 database with the below command.

$ rake db:create

  • If you don't already know the public IP address of your server, look it up with this command.

$ ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

  • Copy the IP V4 address and use it with this command to start your rails application.

$ rails server --binding=server_public_IP

  • If everything's works fine you can access your application with typing below URL in your browser.

http://server_public_IP:3000


  • Once you got the Rails welcome page it means your application has been installed and configured successfully.

Good Luck and start working with Ruby on Rails Application.


1 comment:

Copyright © 2017 | Aayush Kamboj. Powered by Blogger.