This should be an obvious one. Make sure your distribution is up to date.
sudo apt-get update
sudo apt-get upgrade
Installing RVM
Grab curl and git
sudo apt-get install git curl
Install Ruby Version Manager (RVM).
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm);
Then we need to add the environment variables to our .bashrc file.
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc;
We need to reload the .bashrc, so let us source it.
source ~/.bashrc;
Installing Necessary Libraries
sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf;
Installing Ruby
Now the fun part, installing Ruby. Assuming you have sourced your .bashrc file we will be able to install Ruby
If you want 1.9.2 do the following
rvm install 1.9.2
If you want both, just execute both commands. You are allowed to install as many different versions of Ruby that you want.
Say I want to set 1.9.2 to always be my default when I open a terminal. No problem
rvm --default use 1.9.2
Install all of the essential libraries for Ruby to work.
Installing a MySQL Server
Installing a MySQL server is pretty easy. Just run:
sudo apt-get install mysql-server libmysql-ruby libmysqlclient-dev;
The last two libraries are for the mysql and mysql2 gems to communicate with the local server.
Installing Gems
I highly recommend using gemsets to develop Rails applications with. This is so that you do not screw multiple applications up because you are using different gems and you didn’t want to update a specific gem for a specific application.
All in all, it will reduce headaches, so use it.
To create a gemset
rvm gemset create project
To use a gemset
rvm gemset use project
It is that easy. Use them, love them, live with them. I am developing two different Rails applications that use different versions of Rails and Ruby. Talk about a headache if you weren’t using RVM.
Install Rails
Assuming you have selected the gemset you want to use, let us install Rails
gem install rails
After this point you can create your Rails application like you normally would.
Getting Rails To Interact With MySQL
I had been developing with SQLite3 for a while and figured the smarter route would be to just go ahead an use MySQL
gem install mysql2
Default (sqlite3 backend):
rails /home/myuser/www/first_app
For a mysql back-end. Run this one, if you installed rails with gem:
rails /home/myuser/www/first_app -d mysql
Run this one, if you installed rails with apt:
rails /home/myuser/www/first_app -D mysql
$ mkdir rails_projects
$ cd rails_projects
$ rails new first_app
After creating a new Rails application, the next step is to use Bundler to install and include the gems needed by the app. This involves opening the Gemfile with your favorite text editor:
$ cd first_app/
$ gedit Gemfile
The default Gemfile in the first_app directory.
source 'http://rubygems.org'
gem 'rails', '3.0.11'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri', '1.4.1'
# gem 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for certain environments:
# gem 'rspec', :group => :test
# group :test do
# gem 'webrat'
# end
changes This line
gem 'sqlite3'
To
gem 'sqlite3', '1.3.3'
If you’re running Ubuntu Linux, you might have to install a couple of other packages at this point
$ sudo apt-get install libxslt-dev libxml2-dev libsqlite3-dev
# Linux only
Once you’ve assembled the proper Gemfile, install the gems using bundle install
In Ruby 1.9.2 dont have those packages are included. So
In your Gemfile write this
gem 'execjs'
gem 'therubyracer'
and then run
bundle install
Fetching source index for http://rubygems.org/
.
.
.
cd first_app
rails server
Now open your browser and type the following address in the address bar -
http://localhost:3000
That’s All..now you are ready to ‘Ruby on Rails’ create new Application using simple command and start the server.
sudo apt-get update
sudo apt-get upgrade
Installing RVM
Grab curl and git
sudo apt-get install git curl
Install Ruby Version Manager (RVM).
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm);
Then we need to add the environment variables to our .bashrc file.
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc;
We need to reload the .bashrc, so let us source it.
source ~/.bashrc;
Installing Necessary Libraries
sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf;
Installing Ruby
Now the fun part, installing Ruby. Assuming you have sourced your .bashrc file we will be able to install Ruby
If you want 1.9.2 do the following
rvm install 1.9.2
If you want both, just execute both commands. You are allowed to install as many different versions of Ruby that you want.
Say I want to set 1.9.2 to always be my default when I open a terminal. No problem
rvm --default use 1.9.2
Install all of the essential libraries for Ruby to work.
Installing a MySQL Server
Installing a MySQL server is pretty easy. Just run:
sudo apt-get install mysql-server libmysql-ruby libmysqlclient-dev;
The last two libraries are for the mysql and mysql2 gems to communicate with the local server.
Installing Gems
I highly recommend using gemsets to develop Rails applications with. This is so that you do not screw multiple applications up because you are using different gems and you didn’t want to update a specific gem for a specific application.
All in all, it will reduce headaches, so use it.
To create a gemset
rvm gemset create project
To use a gemset
rvm gemset use project
It is that easy. Use them, love them, live with them. I am developing two different Rails applications that use different versions of Rails and Ruby. Talk about a headache if you weren’t using RVM.
Install Rails
Assuming you have selected the gemset you want to use, let us install Rails
gem install rails
After this point you can create your Rails application like you normally would.
Getting Rails To Interact With MySQL
I had been developing with SQLite3 for a while and figured the smarter route would be to just go ahead an use MySQL
gem install mysql2
Default (sqlite3 backend):
rails /home/myuser/www/first_app
For a mysql back-end. Run this one, if you installed rails with gem:
rails /home/myuser/www/first_app -d mysql
Run this one, if you installed rails with apt:
rails /home/myuser/www/first_app -D mysql
$ mkdir rails_projects
$ cd rails_projects
$ rails new first_app
After creating a new Rails application, the next step is to use Bundler to install and include the gems needed by the app. This involves opening the Gemfile with your favorite text editor:
$ cd first_app/
$ gedit Gemfile
The default Gemfile in the first_app directory.
source 'http://rubygems.org'
gem 'rails', '3.0.11'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri', '1.4.1'
# gem 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for certain environments:
# gem 'rspec', :group => :test
# group :test do
# gem 'webrat'
# end
changes This line
gem 'sqlite3'
To
gem 'sqlite3', '1.3.3'
If you’re running Ubuntu Linux, you might have to install a couple of other packages at this point
$ sudo apt-get install libxslt-dev libxml2-dev libsqlite3-dev
# Linux only
Once you’ve assembled the proper Gemfile, install the gems using bundle install
In Ruby 1.9.2 dont have those packages are included. So
In your Gemfile write this
gem 'execjs'
gem 'therubyracer'
and then run
bundle install
Fetching source index for http://rubygems.org/
.
.
.
cd first_app
rails server
Now open your browser and type the following address in the address bar -
http://localhost:3000
That’s All..now you are ready to ‘Ruby on Rails’ create new Application using simple command and start the server.
No comments:
Post a Comment