[ubuntu] How to Install Ruby on rails in your Ubuntu?
Ruby on Rails, a web application framework. Don't confused this with Ruby. Because Ruby is object oriented, reflective, dynamic programming language. It is quite hard. And the Rails is the MVC (Model-View-Controller)framework. It's installation in Ubuntu can be done in few commands and steps. Now, select the version of Ruby, you want to install on your computer.
Before installing Ruby, you need to install some dependencies first.
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
Next, install ruby using rbenv. it is a simple process first install rbenv and then ruby-built.
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
rbenv install 2.2.2
rbenv global 2.2.2
ruby -v
Now we tell Rubygems not to install the documentation for each package locally and then install Bundler.
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
So, Now you installed ruby and gems on your computers. Next needs to install rails. Ruby on rails commonly called as rails. Choose the version you want to install. 4.2.1 is recommended. Perform the following steps.
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
then,
gem install rails -v 4.2.1
rbenv rehash - [to make the rails executable available.]
So now you are installed Rails, Run rails -v command to make sure everything installed correctly.
Setting Database :
For using mysql as your backend you need to perform the following command. This installation gives you the required files to compile the mysql2 gem, which is Rail used to connect with mysql.
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
Now you are going to create your first Rails application with mysql with in few more steps.
rails new myapp -d mysql
/* Move to your application directory. and then create the db*/
rake db:create
rails server.
Now the rail server starts. Just open a browser and type the URL as http://localhost:3000
, WOW your site is working now. Do you have any doubts, ping us. Ohhhh, are you surfing any other services, go ahead.