I had the exact same problem. I tried the other solution suggested here and that didn´t work for me on Ubuntu.
Here is the solution:
Ubuntu
mkdir /lib/ruby/gems/1.8/gems/rails-{whatever your version is}/lib
Depending on which combination of environment versions you're using, some users have given the feedback that this works for them instead:
mkdir /var/lib/gems/1.8/gems/rails-{whatever your version is}/lib
Basically, the ¨[sudo] gem install rails¨ command expects the /lib folder (at the end) but for some reason it hasn´t been created yet.
If you're not sure what your rails version is for the part where I say {whatever your version is}, type up to "rails-" and then try hitting the tab button. You're on a Linux system, so it'll give you a suggestion or two. If it doesn't, try the alternative line given above. You'll need some try and error here because the directory structure is slightly varied in different versions of rails, it seems.
The source of this solution was the following URL. Hope it helps!
http://www.spritle.com/blogs/?p=915
Mac OS X
If you're having a similar problem on Mac OS X, take a look at this other post as well. Sounds like your work-around is simpler:
Ruby on Rails Beta 3 Install Problem on Snow Leopard