Installing Ruby and Rails on Ubuntu 12.10/13.04 can throw up some errors. I’ve found a method that worked, and wrote a few notes about it.
Please note
_This is a fresh copy of a post I wrote some time ago. It does still work as described. You could read my book that covers this process in much more detail.
I chose to go with RVM because that it was I used with previous versions of Ubuntu. All this work is done on the terminal. To install Ruby and Rails, you need to make sure that you have curl installed:
<code>sudo apt-get install curl </code>
While you are at it, you might as well install Git:
sudo apt-get install git-core
Next, we can install RVM:
<code>curl -L get.rvm.io | bash -s stable </code>
Installing the Dependencies for Ubuntu
Then, and this bit is critical, do:
<code>rvm requirements </code>
You’ll get a list of dependencies that MUST be installed for things to work properly. The list will look something like this:
<code>Additional Dependencies: # For Ruby / Ruby HEAD (MRI, Rubinius, &amp; REE), install the following: ruby: /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config </code>
You have to install the dependencies. Bad things will happen if you don’t.
Well, not really bad things: Ruby/Rails just won’t work.
Next, you need to make sure that RVM is being loaded as a function. And this might present a problem. The usual method is to get on Terminal and do:
<code>source ~/.rvm/scripts/rvm </code>
Re-start Terminal, and then do:
<code>type rvm | head -n 1 </code>
You should get: RVM is a function
as a reply. If you do, great. If not, you’ll need to follow the instructions on the RVM web site here. What you need to do, is get Gnome-Terminal to Run command as login shell
.
Here is how it’s explained on the RVM web site:
“By default, gnome-terminal runs Bash as usual, as a non-login shell, therefore skipping /etc/profile* and executing only the user’s ~/.bashrc. This means that RVM doesn’t load and you get the infamous ‘RVM is not a function’ message.”
(Source: rvm.io)
So when you have done that, and run type rvm | head -n 1
again, you should get the RVM is a function
response.
Installing Ruby
Things should become a lot easier now. To install Ruby, we just do:
<code>rvm install 1.9.3 </code>
RVM will go ahead and download and install Ruby version 1.9.3. Next, make sure that your system is using the newly installed Ruby:
<code>rvm use 1.9.3 --default </code>
We should be good to install Rails now:
<code>gem install rails </code>
The MySQL Gem
You can install MySQL through Software Centre these days. But when you do, make sure you also install libmysqlclient-dev
because the mysql2 gem needs the header files. Otherwise, you will see all kinds of weird error messages when trying to install the gem.
Finally
I am now able to build Rails apps on my Ubuntu 12.10 installation. I’ll update this post if I find anything else that needs a tweak to get it working.
The post Installing Rails On Ubuntu 12.10 appeared first on Andy Hawthorne.