Ubuntu (The latest stable version : 11.10(Oneiric Ocelot), released few weeks ago) is one of the most Linux based popular operating system and gradually becoming more popular among programmers and web developers. C/C++/Java programmers and web developers are rocking with the Ubuntu as it has a bunch of open source development tools available to increase the productivity at minimum or zero cost.
Ruby on Rails is one of the most popular framework for developing web applications using Agile approach. Rails (Latest version : 3.1) is based MVC (Model View Framework). Getting started with Rails has been little messy (On Linux platform) for beginners due to its installation/setup errors, probably due to some missing dependencies (e.g gems).Relax, it’s very simple, you just need to understand few basic things. This post has been written for those who want to get started with ‘Ruby On Rails'(commonly called as ROR) on Ubuntu 11.10 or the rails developers who want to develop cool application with Ubuntu 11.10.
To install ruby on rails in Ubuntu 11.10 (or other similar Linux distribution such as Linux Mint, Debian etc), just follow these simple steps. Although RVM is not strictly necessary but it’s strongly recommended – it will allow you to use multiple versions of Ruby, which may be be required in some cases.
step 1. Install dependencies
Install git : Git is the most popular (as well as fast and efficient; Linux kernel uses it; developed by Linux Torwalds, the same guy who developed Linux kernel) open source version control system. You can install it in one simple command to install it from the official package repository –
sudo apt-get install git
[You could also install git from the source (Download the source code, extract it and execute make && sudo make install
) ]
Install Curl : Curl is a command line tool to get a file from FTP/HTTP/HTTPS server. To install, open terminal and execute the command –
sudo apt-get install curl
step 2. Install RVM (Ruby Version Manager)
Open terminal and execute the command (I assume you’ve already completed the step 1, otherwise first do that) –
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Now, you might have to edit the bashrc file to load RVM in shell session. To do that type –
gedit ~/.bashrc
and add the following line to the end (and save the file)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Then reload the shell session using the command –
source ~/.bashrc
Now you can test whether the RVM has been installed successfully or not. Open terminal and execute the command –
type rvm | head -1
After executing above command you should be getting this output –
rvm is a function
That’s All.. You’ve successfully installed the RVM. Next, you are supposed to install few additional dependencies. To find out those programs type –
rvm requirements
After executing the above command, install the additional packages recommended by RVM –
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
step 3. Install Ruby
Now, it’s time to install the ruby version you want (you’re recommended to use either 1.8.7 or 1.9.2). The generic syntax is rvm use version_name
. It will also install the associated packages such as RubyGems and Bundler.
rvm install 1.9.2
Then select the version, you want to use –
rvm use 1.9.2
If you aren’t sure about the ruby version currently being used, then type –
ruby -v
step 4. install Rails
Finally, you can install the rails gem using a simple command –
gem install rails
That’s All.
Now, create a sample application (just for testing) using Ruby on Rails.
rails new my_app cd my_app bundle install rails server
Then open your browser and type the following address (to see the application running) –
http://localhost:3000
Learning Rails ?
Check out this interactive video course on Ruby on Rails at Treehouse.
Recommended Books/Tutorials for Beginners
- Agile Web Development with Rails (Pragmatic Programmers)
- Ruby on Rails 3 Tutorial: Learn Rails by Example (Addison-Wesley Professional Ruby Series)
- Rails Courses on Code School
Update 1. Fixed some typo in commands! and adds a link in resources!
Update 2. My Rails Application : Railyo – a private job board for rails developers/freelancers.
hi i have install rails but when i want to create new application it show
“Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.” how i will get the gemname will any one please solve my problem
Nice. Very clear installation guide. Thank you very much!
This worked perfectly – thanks for the share.
Looked like a great tutorial, but it didn’t work.
Got this when I wanted to create the project:
/usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:926:in `report_activate_error’: Could not find RubyGem rails (>= 0) (Gem::LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:244:in `activate_dep’
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:236:in `activate’
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:1307:in `gem’
from /usr/local/bin/rails:18
Any ideas?
Found my error. Thougt
sudo gem install rails
would be correct, but it has to be done without sudo
Try running sudo apt-get install rails. If there are still errors, try running again gem install rails. The last part, you can type the following:
rails my_app
cd my_app
script/server
then open your browser and type in http://localhost:3000
This is fantastic! I have wasted three days, and here it is!
I have to run this command to install JS runtime to make it work:
sudo apt-get install nodejs
This is the best tutorial to install ruby on reils,so please follow this tutorial
Thank you for this – solved my gem installation problems.
Been trying to get ruby 1.9.2 working for weeks since my machine would default to 1.8.7 and rvm wasn’t working properly. After trying multiple tutorials, I found this one and it finally worked. Thank you!
This post rocks, thank you so much!
This was the missing step before trying to test the my_app (as stated below) –> sudo apt-get install nodejs
–> Also, it seems that everytime you open a new command line, you need to run: rvm use 1.9.2
Great blog, thx for your efforts.
I had to use
sudo apt-get install
ruby-rvm and alter .bashrc accordingly to /usr/bin/rvm
in addition I had to install rails using apt-get, not gem, but everything else worked great.
This doesnt work at all ! Why it is hard to install RoR on Linux ? Linux Sucks !
Hi I am trying to install ruby on ubuntu 11.04 I have installed the rvm bt when I try to install ruby through “rvm install 1.9.2” command then it gives the following error :-
“Error running ‘tar xjf /home/nitin/.rvm/archives/ruby-1.9.2-p290.tar.bz2 -C /home/nitin/.rvm/tmp/rvm_src_9086 –no-same-owner’, please read /home/nitin/.rvm/log/ruby-1.9.2-p290/extract.log
There has been an error while trying to extract the source.
Halting the installation.
There has been an error fetching the ruby interpreter. Halting the installation.”
Please help me out I am new with ubuntu and hv tried my best to solve this problem but couldn’t.
Please if possible someone help me out
Nice easy tut! I installed 1.9.3 instead, and had to install nodejs as mentioned in the other comments.
Thanks for the guide..
Two thumbs for you.. 😀
when i run bundle install, i got the following error message. Any idea how to resolve it?
Invalid gemspec in [/var/lib/gems/1.8/specifications/tilt-1.3.3.gemspec]: invalid date format in specification: “2011-08-25 00:00:00.000000000Z”
Could not locate Gemfile
Damn, so close everything good up until rails new my_app, then a bunch of crap flows and then:
“from /home/ubuntu/.rvm/gems/ruby-1.9.2-p318/gems/bundler-1.1.0/bin/bundle:13:in `’
Fetching gem metadata from https://rubygems.org/.Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Thanks!”
Now stuck
Thanks for valuble Information