How to install Rails 3.0 and Ruby 1.9.2 on Ubuntu
Published 9/1/2010 7:30 PM by Toran Billups 94 Comments
When ruby on rails 1.0 was released back in 2005 it was all the rage. And being someone who was often distracted by the next great web framework I decided to have a look. So in early 2006 I built a small application to see what all the hype was about. I immediately saw the value of a strongly opinionated framework, something the average asp.net developer like myself didn’t know much about at the time.
Fast-forward to August 29th 2010 - Rails 3.0 was released. Just prior to this release I started looking at the web framework again and because I always strive for the optimal developer experience it meant I would need to quit my windows addiction. Not that you can’t do ruby development on windows, but most of the time it’s not worth the pain.
With that said, I paved my development machine and installed Ubuntu 10.04. But as I started looking around for a "how-to" of sorts on installing rails 3 with ruby 1.9.2 I couldn’t find a simple guide that got me up and running error free. Each time I started with a vanilla install of Ubuntu and ended up with what felt like a "hacked together" development environment. But last night I decided to give it another try and document the steps needed for someone like me coming in with minimal linux experience.
Install RVM 1.0.1
First be sure to do a quick update before you get started.
sudo apt-get update
Next install curl and git so we can pull down ruby via rvm
sudo apt-get install curl git-core
Next you need to get the tar.gz for rvm 1.0.1
http://rvm.beginrescueend.com/releases/rvm-1.0.1.tar.gz
extract the contents and cd into the extracted directory when finished
tar xvzf rvm-1.0.1.tar.gz
Once inside the extracted directory run the installer from the command line
./install
After this is complete you need to edit your .bashrc file. First cd ~ and then Type "gedit .bashrc". Put the following at the bottom of the file.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
after you complete the above and save your changes, close gedit. Next close your terminal window and re-open it. Now if you type "rvm -v" you should see a valid version 1.x
Install Ruby 1.8.7
First you need to pull down a few development packages
sudo apt-get install libruby1.8 zlib1g-dev libssl-dev libreadline5-dev build-essential
Next you need to install ruby 1.8.7 through rvm
rvm install ruby-1.8.7
After this is complete you need to set ruby 1.8.7 as the default for rvm
rvm use ruby-1.8.7 --default
Install rubygems and other dev essentials
first you need to add the ubuntu-on-rails ppa repository, sometimes they have newer versions of some Ruby components.
sudo add-apt-repository ppa:ubuntu-on-rails
After you add this be sure to do another update
sudo apt-get update
Next install the essential ruby packages
sudo apt-get install ruby rubygems irb ri rdoc rake
And a few more packages, odds are you will need them anyway
sudo apt-get install build-essential ruby1.8-dev libopenssl-ruby
After all the packages above are installed, add the gem path to your global PATH, so that executables new gems can be easily called from the command line.
export PATH=/var/lib/gems/1.8/bin:$PATH
After you run the above command, close the terminal window and re-open it.
Install Sqlite3
Install the sqlite development packages
sudo apt-get install sqlite3 libsqlite3-dev
Install the sqlite gem
gem install sqlite3-ruby
Install Ruby 1.9.2
Next you need to install ruby 1.9.2 through rvm
rvm install ruby-1.9.2
After this is complete you need to set ruby 1.9.2 as the default for rvm.
rvm use ruby-1.9.2 --default
Install Rails 3.0.0
Now install rails but be sure you DON’T use sudo
gem install rails --version 3.0.0
After you have both rails 3 and ruby 1.9.2 up and running, install the sqlite gem again.
gem install sqlite3-ruby
Now you should have a fully functional rails 3 + ruby 1.9.2 development environment! You can verify this by doing a simple "ruby -v" and "rails -v" from the command line.
Thanks so much I'm going to follow these steps to install tonight...!
Hey, nice guide :). If you do not want to use RVM, checkout the alternatives: http://rbjl.net/19-rubybuntu-1-installing-ruby-and-rails-on-ubuntu (but of course, rvm is great!)
Thanks a lot for your effort, install complete :) NB After this command: rvm use ruby-1.8.7 --default I got error: Binary 'rake' not found in path. But this is minor, rake has been installed several lines below in article.
I got the same error Raynor mentioned. Any clues?
As @Raynor mentioned you will get an error that says 'rake' not found, but down below you install it and everything works as expected. Sorry I didn't document this error initially, but I found everything still works as long as you follow the guide.
Wow. This worked the first time. In installed Ubuntu 10.4 and rails both in under 20 minutes or so. Usually I spend a few days fiddling with commands to get things just right. THANKS!
Thanks much! Very helpful.
Interest, I keep getting: Using /usr/local/rvm/gems/ruby-1.8.7-p302 ln: creating symbolic link `/usr/local/rvm/bin/ruby': No such file or directory ln: creating symbolic link `/usr/local/rvm/bin/gem': No such file or directory ln: creating symbolic link `/usr/local/rvm/bin/irb': No such file or directory ln: creating symbolic link `/usr/local/rvm/bin/ri': No such file or directory ln: creating symbolic link `/usr/local/rvm/bin/rdoc': No such file or directory ln: creating symbolic link `/usr/local/rvm/bin/rake': No such file or directory ln: creating symbolic link `/usr/local/rvm/bin/erb': No such file or directory ln: creating symbolic link `/usr/local/rvm/bin/testrb': No such file or directory When I try to run rvm use ruby-1.8.7 --default Any ideas?
@Doctor Sushi you must have installed rvm using super user. You installed rvm globally above so now when you run rvm it will require super user (ie- why you can't create the symbolic link above in the error message). You will need to reinstall rvm locally so I would recommend reinstalling Ubuntu fresh and following my instructions above.
Thanks a milli for this awesome walkthrough
Worked perfect! Now I just hope someone has written a tutorial this straightforward for setting RoR up with Apache or lighttpd and MySQL.
I ran into a problem but I'm not sure if things are missing because Aptana RadRails installed gems during the initial setup or if they're just missing. I created a testapp and tried to initialize the WEBrick server but the script/server is missing. The only file in the script folder is rails. Is there a way to reinstall Rails so I get the WEBrick server? Even better, is there a way to install the WEBrick server and get the missing script in my testapp?
@Josh you should be able to fire up WEBrick using the command "rails server" from the directory rails created for the web application.
Thanks for this tutorial, mate! It's been a pain for me to get rails 3 to work on Linux and Mac OS lately - ruby 1.9.1 issues, sqlite3 lib missing, etc.. You've been extremely helpful.
Hi I have ruby 1.8.7 and Rails 2.3.8 running in Ubuntu 10.04. So far thy run fantastic but I want to update to Ruby 1.9 and Rails 3. Of course I don't want to mess up my working versions and don't want to run both, I just want to run the two new components. Have you any knowledge of how can I do that? Thanks in advance
Great post. This was my third attempt to get Ruby 1.9.2 and Rails 3 working on Ubuntu 9.1 and it worked perfectly. There was one extra step just before running "sudo add-apt-repository ppa:ubuntu-on-rails" I needed to run "sudo apt-get install python-software-properties" Thanks!
Thank you, great tutorial. I am up and running. Had the RAKE issues as mentioned above but everything is working well.
What's wrong with using sudo when installing the rails or sqlite gems? Thank you!
I just confirmed that this worked on Ubuntu 10.10 (Maverick Meerkat) too. I had tried to piece together a half dozen "How To" articles for installing RVM, Ruby 1.9.2 and Rails 3 to no avail. Thanks for putting this together.
Thanks a lot, it worked like a charm here in my Ubuntu 10.10
Thank you for the instructions. I'm a newbie and this definitely helped me!
Very helpful. I had trouble installing Rails, getting the message: ERROR: Loading command: install (LoadError) no such file to load -- zlib... I followed the instructions at rvm.beginrescueend.com/packages/zlib and now everything seems to be working.
Great stuff. I had trouble with the bashrc file, and had to type gedit ~\.bashrc in order to edit the file. Everything else went smoothly. THANKS!
Thanks for the tutorial, excellent job. You helped me out a lot tonight. The only thing I would change is update the rails gem command to 3.0.3.
Thanks a lot!! Very helpful. Finally I'm aboard!! (I try to install on Debian Lenny but I can´t: too many troubles with sqlite3 instalation) ¿Some post about it? I wait for it! Again, thanks and Cheers!
Many thanks Toran, nice clear and easy to follow instructions - if only everything was so well documented! Keep up the great work -Phil.
Thank you very much for sharing this... The only thing I did except your steps was: gem install mail because installing rails complained with: Error installing rails: mail requires i18n (~> 0.5.0, runtime) Everything else was accurate...
"You will need to reinstall rvm locally so I would recommend reinstalling Ubuntu fresh and following my instructions above." I appreciate the problem here, but this is pretty outrageous - don't you think? I can't laugh at Windows users for having to reinstall their OS anymore at any rate - that if typing 4 extra characters before installing something results in a situation where you may be better off reinstalling the OS from scratch. Surely there's a better way?
Thank you. Worked well!
hi...I used the above commands and to install rails I used sudo gem install rails --version 3.0.1. The command ran fine with no error. But when I do rails -v it throw error rails command not found. What could have gone wrong. Will appreciate any help on this. Thanks!
If your purpose is to end up with Ruby 1.9.2, and use RVM to install it, why you do previously go through installing ruby-1.8.7 with rvm, and then install yet again another version with `sudo apt-get install ruby rubygems irb ri rdoc rake`? Won't `rvm install ruby-1.9.2` right after installing rvm just install everything needed (including rubygems irb ri rdoc rake)?
Thanks for this. I had to install a few gems by hand before rails 3.0.0 would install - abstract, mail, thor as I recall.
@PandaWood: remember the OP said he had limited Linux experience. Clearly, installing an application incorrectly does not require the reinstall of Ubuntu. Normally you would use apt to remove the app. In this case, the install script from the rvm tarball did the installation. You need to look at that install script to see what it did and undo it if necessary. Imagine, in the Windows world, if an executable setup didn't come with an uninstaller. However, in Linux, you don't have to worry about deciphering, locating and deleting a dozen registry entries. If someone were to package rvm then it would be trivial. Maybe you only need to re-install as non-root and you'll be done.
This has been a LIFE SAVER, but I would suggest changing your rvm step to show: bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ) from http://rvm.beginrescueend.com/rvm/install/
Thanks! That was really helpful.
Hello, everything went well but when i type rails -v, got the message below. The program 'rails' is currently not installed. You can install it by typing: sudo apt-get install rails Please help.
I just want to note that this works for Jolicloud as well. Thank you very much for the walk through!
nice guide. i just wanna understand why apt-get install ruby, i thought rvm took care of that.
Many thanks for the great tutorial. A few suggestions for improvement: 1. Install RVM using "bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )", as noted on the RVM site, so the latest version is installed. 2. Follow the RVM installation's instructions to edit .bashrc to convert any [ ... ] && return expressions into if-fi pairs, with the "fi" just before "[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" at the end of the file. 3. Omit the section "Install rubygems and other dev essentials". This installs a separate copy of Ruby 1.8.7 on the system, redundant with the one installed by RVM.
Thanks for this great tutorial. Being a newbie I appreciate such crystal clear instructions. Took the pain out of the installation to be sure.
Thanks a lot! (A fellow asp.net developer interested in RoR)
nice man..nice guide..
Great howTo! It's been useful several times to me :)
Thanks a lot! grate guide.
I thank you very very much for the walkthrough, there aren't really good ones out there... I get this error all the time: /usr/local/lib/site_ruby/1.8/rubygems.rb:861:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError) from /usr/local/lib/site_ruby/1.8/rubygems.rb:255:in `activate' from /usr/local/lib/site_ruby/1.8/rubygems.rb:1204:in `gem' from /var/lib/gems/1.8/bin/rails:18 AND if i use gem install rails --version 3.0.0 I also get an error: ERROR: Loading command: install (LoadError) no such file to load -- zlib ERROR: While executing gem ... (NameError) uninitialized constant Gem::Commands::InstallCommand What am i'm doing wrong...?
Forget to tell you when to get the error... When i do rails -v in the terminal...
Thank god it works!! I just re-installed ubuntu again and did exactly the above and it worked!! Thanks again!!! Regards, Thijs
Thank you, thank you, thank you. Everything worked on the first try with my new fresh install of PinguyOS. I remember spending hours trying to get rails 3 up on Ubuntu which is why I was dreading installing Pinguy. So thank you it went smoothly. On a side not if any one needs to do a fresh install a switch to PinguyOS might not be a bad idea its freaking sweet and thanks to you its on RAILS :). God I am a geek.
Thanks man, this is awesome, bookmarked :)
very nice guide!! at the end I0ve this problem: asd@pietro-FG5L:~$ gem install rails --version 3.0.0 ERROR: While executing gem ... (Gem::DependencyError) Unable to resolve dependencies: mail requires i18n (~> 0.5.0) asd@pietro-FG5L:~$ what's that?
[resolved] I installed also "mail": $>gem install mail ...... $>gem install rails --version 3.0.0 ....ok...
Thanks a lot!!!
Thanks! Everything worked great. This really helped me to use rvm, too - I was missing some of the development packages in Ubuntu.
Thank you so much for sharing! It was really helpful Before installing Rails3 I had to update ruby to 1.9.2p180 to avoid problems, rvm update --head && rvm reload && rvm install 1.9.2 && rvm 1.9.2 --default before Rails3 install does the trick...
Terrific post (along with a few of your others as well).
simply awesome... :) thanks..saved a lot of time now i wanna it for centOS
Wow, what a walk through! I didn't follow the instructions 100%, but everything worked just like you said it would.
To everyone who said thanks you -it was worth the many hours I spent installing Ubuntu (over and over) to get it exactly right! Glad I was able to save someone else a lot of time and energy!
After yesterday's remarkably frustrating night, I realised that this was the only way to get Rails up and running on Ubuntu, and took your suggestion to reinstall the OS and followed the instructions step by step. Voila! Everything worked. Thanks a million!!!
After this command gem install sqlite3-ruby I get error message ERROR: http://rubygems.org/ does not appear to be a repository ERROR: Could not find a valid gem 'sqlite3-ruby' (>= 0) in any repository But with a little patience and persistence it all worked out. Thanks a million times
@Trebla I did not get the same error as you did but when I installed rails a little message pop-upped saying that it's not called sqlite3-ruby anymore it's just sqlite3. So try to install the gem sqlite3.
Hi and very thanks to this article, this is helpful really (^_^) When I try to do these steps, on this command: gem install sqlite3-ruby I get this error: ERROR: Loading command: install (LoadError) no such file to load -- zlib ERROR: While executing gem ... (NameError) uninitialized constant Gem::Commands::InstallCommand Help me please, I'm new to Linux and Rails ): Thank you very much Javad.Darvish.Amiry@gmail.com
Hi, I receive below error when I install the rails. Any thoughts why I'm getting this error. thiru@ubuntu:~$ gem install rails --version 3.0.0 ERROR: Loading command: install (LoadError) no such file to load -- zlib ERROR: While executing gem ... (NameError) uninitialized constant Gem::Commands::InstallCommand thiru@ubuntu:~$
Thank you so much! You are the best
Everything works fine until I try to do gem install rails --version 3.0.0 Gives me the error as follows: ERROR: While executing gem ... (Errno::EACCES) Permission denied - /home/tuomas/.gem/specs Instructions say explicitly to not use sudo, and trying to run sudo ~/.rvm/rubies/ruby-1.9.2-p0/bin/gem update --system it gives RuntimeError saying this might break my Debian system. W/o sudoing it gives the same error as the previous one. The suggested way of getting rails from apt-get doesn't offer me 3.0. I'm quite in a loss here, please help. Thank you in advance!
In response to previous comment, I found solution. The ~/.gem was owned by root, so gem install couldn't use it w/o sudo, and thus couldn't install gems. sudo rm -rf ~/.gem resolved the problem, and I could finish the process. Thanks for a good guide!
Excelente y Gracias ! It works without any trouble, nice written, thanks for your sharing your knowledge.
On this step: $ rvm use ruby-1.8.7 --default I got the following message: Database file /home/bubble/.rvm/config/user does not exist. info: Using ruby 1.8.7 p334 What does the previous message imply? Sorry I am a newbie on rails.
thank you very much! :D
thank you very much! :D
Thank you so much for the effort taken! appreciate it :)
Thanks a lot!!! :-)
thanks alot this was quite useful. i used instructions in other sites & they all failed but this one worked withoutb stress. keep it up!
Boss tutorial, boss.
Boss tutorial, boss.
Thanks for documenting this process... I struggled for two days before stumbling upon this document. It helped a lot!!!
For ubuntu 11 i had to manually add the path to .bashrc. the export command did not work for me. just in case it helps anyone.
Thank you very much for taking the time and writing this guide. Helpful and time-saving, regards.
Thank you very much for taking the time and writing this guide. Helpful and time-saving, regards.
Thanks a bunch, this website has the details that can install Ruby and Rails just flawlessly. Now I dont know if it's the Ruby intallation or is it my Ubuntu, but whatever it is, just turned out to be without any hassle. Thanks. Maulik
I can't believe how obscenely difficult it is to install the latest ruby/rails on Ubuntu. Thank you very much for your walkthough. I've been tearing my hair out over this, but it worked perfectly. Cheers
Wow this guide helped me a lot! Worked on the first time! unlike most of the setup guides I found. Thanks for the great work.
Thanks to this Ubuntu/Rails guide I was able to setup RVM/Ruby 1.9.2/Rails 3.0.1 with only one stumbling block. When I attempted to install rails I got the same error message mentioned by Thiru: ERROR: Loading command: install (LoadError) no such file to load -- zlib ERROR: While executing gem ... (NameError) uninitialized constant Gem::Commands::InstallCommand I read Luke's post about the zlib package: rvm.beginrescueend.com/packages/zlib After reinstalling ruby 1.9.2 with zlib I determined that Ubuntu simply could not determine the path to gem in order to run the gem install command. To confirm my findings I ran the following: $ which gem Then which command returned the path to gem. I ran the gem install command again using the full path. In the command below replace "path/to" with the path returned from previous command. $ /path/to/gem install rails --version 3.0.1 Something so simple wasted a few minutes of my time but now I have everything up and running. Thanks Toran! Thank you also to all the other posters for sharing their experiences and knowledge.
for anyone who don't wanna see the annoying message about file "lib" not found (believe me, dont try to solve it, coz it is not worth to do that), in the stage of installing rails framework, use gem install rails --version 3.0.10 --no-rdoc --no-ri
Great tutorial, thanks. I had problem before I saw this one. So nice :)
Hi can anyone help me with the following problem: Ubuntu 11.04 Terminal: freddy@blabla:~$ rvm install ruby-1.8.7 info: Installing Ruby from source to: /home/freddy/.rvm/rubies/ruby-1.8.7-p302 info: Extracting ruby-1.8.7-p302 ... error: Error running 'bunzip2 < "/home/freddy/.rvm/archives/ruby-1.8.7-p302.tar.bz2" | tar xf - -C /tmp/rvm_src_1785', please check /home/freddy/.rvm/log/ruby-1.8.7-p302/extract*.log error: There has been an error while trying to extract the source. Aborting the installation. error: There has been an error fetching the ruby interpreter. Aborting the installation. freddy@freddy-Satellite-A100:~$ I keep getting these error messages andI have no clue how to fix it. Thanks very much! Freddi
Awesome!!!!!!!!all things are working well
Thanks! Installed perfectly. No issues with any previous semi-complete installs either.
Hi.Thanks for your blog entry. In Kubuntu 11.10, sslv2 has been deprecated, and the installation of ruby-1.9.2 gives a compiler error. For correcting this you must make first: rvm package install openssl rvm package install readline. After this, install ruby-1.9.2 with: rvm install 1.9.2 --with-openssl-dir=$rvm_path/usr --with-readline-dir=$rvm_path For me this has worked fine.
Thank you Toran for providing flawless concise steps for setting up Ruby on Rails on Ubuntu 10.04.
thank you! get lots of helps
I found another way: sudo apt-get install ruby ruby-rvm nodejs sudo rvm package install openssl sudo rvm install 1.9.2 --with-openssl-dir=$rvm_path/usr sudo rvm --default use 1.9.2 rvm-shell rvmsudo gem install rails Just make sure to rvm-shell to enter the correct environment.
Sorry, I didn't know the newlines were removed. I'll separate the commands with (): (sudo apt-get install ruby ruby-rvm nodejs) (sudo rvm package install openssl) (sudo rvm install 1.9.2 --with-openssl-dir=$rvm_path/usr) (sudo rvm --default use 1.9.2) (rvm-shell) (rvmsudo gem install rails) Make sure to rvm-shell to enter the correct environment.
great job!!