This is a short guide on how to get Rails 3 (which is still in beta) running on Ubuntu Lucid Lynx. I’m going to assume that you have some skill with the terminal. Also, since you can’t have one without the other, I’m going to walk you through through installing Ruby 1.9.2 and also sqlite3. So there it goes.
First, let’s install all of the necessary tools and libraries:
apt-get install curl git-core build-essential zlib1g-dev libssl-dev libreadline5-dev
Install ruby 1.9.2 using RVM. Refer to the official RVM instructions here. Make sure you have curl and git installed (from above) and run this command:
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Then add this line as the last line in your .bashrc:
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi
Close your terminal and open a new one, then run the following to test RVM install:
rvm notes
Next, you can begin ruby 1.9.2 installation by running:
rvm install 1.9.2
The install will take up to several minutes and once it completes you have to set ruby 1.9.2 as the default version:
rvm --default ruby-1.9.2
Then you can test your new ruby install:
ruby -v
And now, to install Rails 3 simply type in your terminal:
sudo gem install rails
The above line should be all you need, as it will take care of installing all of the pre-requisite gems that Rails 3 needs, like rack and bundler.
[ad code=1 align=center]
Give your new install a test by creating a test application:
rails testapp
From here on you can start creating and testing your application further. I’ll note that this guide did not cover the setup for the database, whether it be mysql or sqlite.
Quick SQLite quide:
If you want to get a quick database up and running with sqlite, then you’ll need to sqlite3 and the libsqlite3-dev packages:
sudo apt-get install sqlite3 libsqlite3-dev
Then you can install the sqlite gem:
sudo gem install sqlite3-ruby
That should properly install sqlite3 that is necessary for simple Rails 3 database function. You can now successfully run the server for you app.
Make sure you are in your test app directory and run:
rails server
or (even better):
rails s
If you enjoyed or found this post helpful, please leave a comment. Also, if you found some mistakes or have a tip on how to improve this installation process, don’t be shy and tell me about it.
Related posts:
It’s fine tutorial however please pay attention to release notes
Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash Rails 3.0.0. Ruby 1.9.1 OUTRIGHT SEGFAULTS on Rails 3.0.0, so if you want to use Rails 3 with 1.9.x, jump on 1.9.2 trunk for smooth sailing.
Thanks for the tutorial!
Note that you don’t generally need the ‘sudo’ in
sudo gem install rails –pre
and
sudo gem install sqlite3-ruby
since RVM installs ruby to your home directory (unless of course you would like a system wide install).
First, I have the Hardy version that comes with turnkey. I had trouble installing rails 3. It gave an error that said:
ERROR: Error installing rails:
activesupport requires Ruby version >= 1.8.7
But I had updated to 1.9.2 already.
Looking on the rails site I saw that they said to run another gem install before installing the new rails, which worked for me. This is the command before the install rails command that they said to run:
gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
This saved my life.
I was having so much trouble before I installed this. Now I’m on Ruby 1.9.2 and Rails 3 with no issues (so far). Thanks!
1 note about RVM. And a comment on someone’s gist in github helped with that. You have to have ruby installed to use rvm. Before trying rvm, I removed all Rubies. And that didn’t work. So I went back and installed 1.9.0 the fired up rvm to do 1.9.2 and all was well.
best,
Kevin
Hey!
I’ve tried the directions given on this page. The output of relevant commands on my machine is as under:
~$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29034) [i686-linux]
~$which ruby
/home/alwin/.rvm/rubies/ruby-1.9.2-head/bin/ruby
~$echo $PATH
/home/alwin/.rvm/gems/ruby-1.9.2-head/bin:/home/alwin/.rvm/gems/ruby-1.9.2-head@global/bin:home/alwin/.rvm/rubies/ruby-1.9.2-head/bin:/home/alwin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin/:/sbin:/bin:/usr/games
I’ve created a directory “rubydev” in my home directory and using “rails new hello” in I’ve created a dummy web app in that directory.
But when I try to execute the command “ruby script/generate controller App” or any such related command from the folder “~/rubydev/hello” I get the following error:
ruby: No such file or directory — script/generate (LoadError)
Can you please help me resolve this problem?
Thanks
Alwin
In Rails 3 you should be using:
rails generate controller Users
or simply
rails g controller Users
when you are using rvm you should be using sudo to install gems.
ex:- Not sudo gem install X but gem install X.
I was able to do all of this by first installing the LAMP setup.
sudo apt-get install apache2 mysql-server php5
Once these were installed:
sudo add-apt-repository ppa:ubuntu-on-rails/ppa && apt-get update
sudo apt-get install rails
This installed Ruby on Rails and all the dependencies. It even setup the document root to the correct location /var/www.
I’m following these instructions to the letter, but when I run rvm –default 1.9.2 I get the following output:
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
On a fresh install of 10.04.
There is no need for an existing copy of ruby on your system!
ln: creating symbolic link `/usr/local/rvm/bin/ruby’: No such file or directory
RVM should be in /home/username/.rvm
I am using Ubuntu 10.04 and I didn’t need to do anything extra to install rubygems.
yeah, i thought the RVM website said don’t use “sudo” when using “gem install “, so “sudo gem install rails” might be better if it is “gem install rails”?
Followed the instructions, and then:
sudo gem install rails
Successfully installed rails-3.0.1
1 gem installed
Installing ri documentation for rails-3.0.1…
File not found: lib
Any ideas on how to get by this one?
i’ve got an error with
sudo gem install rails
saying :
“gem : command not found”
I tried
gem install rails
and it works better
Damn, this was the bizomb. Thanks for the tutorial. I spent a few hours trying to figure out how to get this right on my linux install. I tried a few ways, all on top of each other, and I’m sure that botched things. This went way smooth.
Just a note – trying:
$ gem install sqlite3-ruby
Hello! The sqlite3-ruby gem has changed it’s name to just sqlite3. Rather than
installing `sqlite3-ruby`, you should install `sqlite3`. Please update your
dependencies accordingly.
Thanks from the Ruby sqlite3 team!
and
$ gem install sqlite3
did something different. I too noticed that if I installed rvm as me, my gem installs needed to not use sudo – in particular, I (local user) have ruby 1.9.2 but the system/root has 1.8.7.
try create the lib directory inside gems/1.8 directory
and /ruby/1.8 too I create in these directories but I believe only in gems/1.8 is needed. Someone confirm this please.
If you want use ruby 1.9.2 use RVM and don’t use the sudo command for nothing you need be logged with you normal user all commands executed on prompt user root $ ok.
Oh thank you thank you so much. That was so helpful. I was stuck trying to get Rails to work on my computer for days and this fixed it.
One possible error I noticed…
“rails testapp” should be “rails new testapp”
But anyway that is minor, thank you so much!!
any time you see “sudo gem install” change it to “rvmsudo gem install” because rvm does not support sudo.
Hey,
Overall, its great, but the part about RVM is a bit outdated or just did not work. After installing using the current info on the RVM site, the rest was dead on. Thanks a lot for the info!
It should clear that this is for a local development machine. Not production. You can find a deployment script on RVM’s site. Personally I think a direct install is just easier for production. Note that if you use Passenger you are limited in versioning.
Also rubinius 2.0.0pre is out today (6/8/11)