The first challenge I faced when I started using Ubuntu was moving my Wubi installation inside Windows to a separate partition. Thats when I understood how one should find his/her way around the problems they face using Linux. Linux has one of the biggest support base on the internet. You can find solutions to almost all problems you face in the web. The only thing you need to do is a simple and proper Google search and you’ll fix whatever problem you have in not time at all! But unfortunately many who are new to this whole idea find it really difficult using Linux. This is because they are completed immersed in and used to the way Windows works. And so whenever they face some problem in Linux, like a dependency issue, they call you or text you and ask you to fix their problems. Unlike in windows where you get generic error messages with an error code, Linux provides verbose details about the kind of error that has occurred. People must make use of this information to find solutions to their problems.
Okay enough said! When I started learning Ruby I wanted to install Ruby on my Ubuntu 11.10 installation. But I really didnt know that I already Ruby pre-installed! Not knowing this I started installing Ruby and I faced a lotta issues. I had no idea what was happening. Then I tried removing Ruby. Then after my failed attempts to remove Ruby completely I installed RVM. Then I installed a Ruby version via RVM. But then gems like rails etc just wouldn’t install. Me being a Linux beginner back then found it really irritating and annoying to the extent that I considered dumping the whole idea of learning Ruby. But the pure elegance of Ruby and the thirst to learn Rails made me keep pushing. Finally after two days I got Ruby and Rails working on my PC without re-installing Ubuntu :P. Since then I’ve made several Ruby and Rails installations on many computers. I faced a lotta issues, especially dependency problems when installing Ruby, Rails, MySQL etc. So I decided to write this post to tell those beginners out there, the stuff they would need to properly install Rails etc.
Before starting the installation process we need a special package that contains tools for building packages from their source code. You will be needing those tools during the process (you will not be using it directly. do not fret). Installing this is a piece of cake. Just run
apt-get install build-essential
And your’re done!
Okay lets begin installing Ruby and Rails. First off, we will install Ruby. Fortunately you already have what you need to install Ruby in a fresh Ubuntu 12.04 distro. We will install Ruby using the following command.
sudo apt-get install ruby1.9.3
This will install Ruby 1.9.3 which is the latest version currently.
Now let us make sure we have MySQL and Apache in our system. Try running
If this tells you the Apache Server version then you have apache in your computer. Then try following command,
If this tells you the MySQL database version, then you have MySQL too.
If you donot have MySQL or Apache no need to worry. You can install them easily using following commands.
sudo apt-get install mysql-server
sudo apt-get install apache2
Now we need some dev tools and build tools in our system because many gems have to be built locally. And a fresh Ubuntu 12.04 distro DOES NOT HAVE below tools. Run the following commands.
sudo apt-get install ruby1.9.1-dev
sudo apt-get install libruby
sudo apt-get install libopenssl-ruby
The above commands will install the necessary headers and other tools used to build various gems.
The following two commands will install certain lib headers that may be used by some gems that allow you to work with XML and HTML like the Nokogiri gem that parses XML.
sudo apt-get install libxslt-dev
sudo apt-get install libxml2-dev
Now to get mysql2 gem installed we need the following package.
sudo apt-get install libmysqlclient-dev
Passenger with Apace2 or Nginx is by far the most popular deployment option for Rails. Inorder to get Passenger installed you need following support packages.
sudo apt-get install libcurl4-gnutls-dev
sudo apt-get install libssl-dev
sudo apt-get install apache2-prefork-dev
sudo apt-get install libapr1-dev
sudo apt-get install libaprutil1-dev
Now we have got all the support packages needed. Lets install Rails. We do this by running the following command.
sudo gem install rails
You could use SQLite that comes along with Rails as your database. But many prefer MySQL or PostgreSQL which are more stable and can handle high volumes of data. We will use MySQL. Inorder to use MySQL from a rails application you need the mysql2 gem. To install this we need to run the following command.
gem install mysql2
When you run the “rails server” command Rails starts either the WeBrick or Thin server depending upon your configuration of the Gemfile. But these servers are okay only for development purposes. When you deploy your application you need a much more powerful server like the Apache server. But the Apache server by itself cannot help you deploy rails applications. For this we need an Apache module called Phusion Passenger. I will be covering this in a future post. For now we have a complete Rails Development Environment setup.
Create a new rails project and code away! 😀
Oh and I forgot. For those of you who want to manage your code and collaborate with people, install git using the command,
sudo apt-get install git
You can then register at Github.com and start using it. Tutorials on how to use Git and Github can be found at
I will cover Git basics in the near future. I will also be covering deployment to Heroku which is a really cool application host in coming weeks.
Please note that Ruby, Rails and the other packages we installed now are actively being developed. And you might get newer versions. The above mentioned packages are the latest stable versions currently. And even if you have installed all the supporting packages that I told you, you could face some issues while setting up because the setup in your computer might be different.. Dont fret. Just copy significant part of the error message and do a Google search. You could also browse askubuntu.com to get solutions to many Ubuntu specific problems.
So what are you waiting for? Install Rails and start rolling out your web applications. Who knows? Your idea could be the next big thing in the internet!
Have fun 🙂