So finally, after having waited in my to-do list for reasonably long time, Ruby and Rails is installed on my Ubuntu 12.04 (the proven, practical and precise OS). Yes, I did a fresh install of Ubuntu 12 after the upgrade from Ubuntu 11 rendered the OS respond slow (Ubuntu team, are you reading this?).
But, I am more excited about Ruby on Rails. If you haven't heard of it yet, you need to catch up. Visit its homepage here.
This post is going to talk about installing Ruby on Rails (I will call it Rails henceforth going by the common term) which can be a real pain at times. And sadly, there are not many good documentation out there on it.
During my writing of this blog, the current versions I used are Ruby 1.9.3 and Rails 3.2.3. This post shows how to install Ruby, Rails and finally the Bundler using RVM (Ruby Version Manager). However, there is a simple way to install the entire package called the Railsready script that installs all the required packages at one go, and is quite simple. I wanted to get into the nitty-gritties! ;)
You need to do some checks first:
Type the following command in the terminal.
Step 2: Update the libraries
You should update the libraries to make sure you have all the latest ones. This can save you from quite some trouble due to missing libraries during installation.
Step 3: Install Git and Curl
Since we will be using RVM (Ruby Version Manager), we need to install Git and Curl, if we do not already have them. Git is the source control repository (as you might know by the GitHub fame) nd Curl is a command line tool to get data from a URL.
Step 4: Install Ruby Version Manager
Ruby Version Manager (RVM) is very helpful to manage different versions of Ruby on a system. Using RVM is highly recommended (by me!).
To geth the RVM files to our system, we execute the following command at the bash shell.
Step 5: Make RVM load with terminal
To make RVM load itself everytime we open the terminal, we need to edit the bash config file.
Step 6: Install packages required for Ruby
After RVM is installed, its time to install Ruby. But you need to make sure we have all the packages that are required by Ruby (it's better to install all these packages now and avoid a headache later on!).
To check what the requirements are, you can execute:
To install the packages, execute:
Step 7: Install Ruby (1.9.3 in this case)
With all preparations done now, we can go ahead to install Ruby. I used version 1.9.3.
Step 8: Install Rails
Time to install Rails now. This is the main application framework, one that changed the world to an extent! ;)
To install rails, we will use gems, the standard package manager for Ruby. You do not need to use sudo for installing gems.
Step 9: Create a new Rails project
Lets create a new Rails project. My site is called "hellosite".
Step 10: Start the Rails server
In case, you get an error like "ExecJS::RuntimeUnavailable", you need to get some packages installed:
Eh, btw, the server is still running. To stop the server, press Ctrl+C! ;)
I will follow with more posts on this. But an important disclaimer before I close, trying out these commands on your machine should be done at your risk and do not hold me responsible if anything goes wrong. I had these two handly references that made my task easy, and these references have more comprehensive info. You can also refer to Ryan Bigg's installation guide or get the pdf from Mircea Goia's post for more.
This post is going to talk about installing Ruby on Rails (I will call it Rails henceforth going by the common term) which can be a real pain at times. And sadly, there are not many good documentation out there on it.
During my writing of this blog, the current versions I used are Ruby 1.9.3 and Rails 3.2.3. This post shows how to install Ruby, Rails and finally the Bundler using RVM (Ruby Version Manager). However, there is a simple way to install the entire package called the Railsready script that installs all the required packages at one go, and is quite simple. I wanted to get into the nitty-gritties! ;)
You need to do some checks first:
- You need to make sure you have sudo access to the system.
- We will not be using apt-get for the installations. Its outdated and can be quite problematic when installing Rails. Instead, we will use aptitude.
Type the following command in the terminal.
$ sudo aptitudein the terminal, and it should open the a visual interface. If you get errors, you have to install aptitude by executing the following commans.
$ sudo apt-get update $ sudo apt-get upgrade 4 sudo apt-get install aptitude
Step 2: Update the libraries
You should update the libraries to make sure you have all the latest ones. This can save you from quite some trouble due to missing libraries during installation.
$ sudo aptitude update $ sudo aptitude upgradeUpgrade will take quite some time. Grab a coffee!
Step 3: Install Git and Curl
Since we will be using RVM (Ruby Version Manager), we need to install Git and Curl, if we do not already have them. Git is the source control repository (as you might know by the GitHub fame) nd Curl is a command line tool to get data from a URL.
$ sudo aptitude install build-essential git-core curl
Step 4: Install Ruby Version Manager
Ruby Version Manager (RVM) is very helpful to manage different versions of Ruby on a system. Using RVM is highly recommended (by me!).
To geth the RVM files to our system, we execute the following command at the bash shell.
$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)Instead of the above command, you can also type:
$ curl -L get.rvm.io | bash -s stable
Step 5: Make RVM load with terminal
To make RVM load itself everytime we open the terminal, we need to edit the bash config file.
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrcNow, close and open the terminal again. Or you can get the same effect by this command:
. ~/.bashrcTo check RVM is installed and to read the notes, you can execute:
$ rvm notes
Step 6: Install packages required for Ruby
After RVM is installed, its time to install Ruby. But you need to make sure we have all the packages that are required by Ruby (it's better to install all these packages now and avoid a headache later on!).
To check what the requirements are, you can execute:
$ rvm requirementsThere should be quite some packages enlisted. Some of them, if they are already installed, like git and curl, will not be installed again.
To install the packages, execute:
$ sudo aptitude 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
Step 7: Install Ruby (1.9.3 in this case)
With all preparations done now, we can go ahead to install Ruby. I used version 1.9.3.
$ rvm install 1.9.3This should install Ruby just fine. If you have multiple versions of Ruby on your machine, you can make use this version by:
$ rvm use 1.9.3, or even better, make this version as default:
$ rvm --default use 1.9.3Check which version of Ruby you are using by,
$ rvm -v
Step 8: Install Rails
Time to install Rails now. This is the main application framework, one that changed the world to an extent! ;)
To install rails, we will use gems, the standard package manager for Ruby. You do not need to use sudo for installing gems.
$ gem install rails -v 3.2.3Check the version of rails that was just installed.
$ rails -vCongratulations, your installation is done. You can try out now creating a new Rails project.
Step 9: Create a new Rails project
Lets create a new Rails project. My site is called "hellosite".
$ rails new hellositeThis should start the bundler, that is responsible for managing application's dependencies. In case, the bundler doesn't start, you can go to the directory of the project (in our case "hellosite") and run the bundler.
$ cd hellosite $bundle installGo to the project's directory and you should see the project created with all different folders e.g. models and controllers and views....we will talk about them in some other post! ;)
Step 10: Start the Rails server
$ rails serverThis command will start the default Rails server called WEBrick.
In case, you get an error like "ExecJS::RuntimeUnavailable", you need to get some packages installed:
$ gem 'execjs' $ gem 'therubyracer'Then go to the project directory and run the bundler again.
$ bundle installand then start the Rails server using,
$rails serverThe WEBrick server runs on port 3000 by default. Once the server is started, you can open your favorite browser, type "http://localhost:3000" and your site should open. There you go, you first Rails project is online! ;)
Eh, btw, the server is still running. To stop the server, press Ctrl+C! ;)
I will follow with more posts on this. But an important disclaimer before I close, trying out these commands on your machine should be done at your risk and do not hold me responsible if anything goes wrong. I had these two handly references that made my task easy, and these references have more comprehensive info. You can also refer to Ryan Bigg's installation guide or get the pdf from Mircea Goia's post for more.