One of my most recent adventures have been around exploring Ruby on Rails. And the first step towards learning any language is ‘Environment Setup’…and trust me it isn’t as easy as it sounds. There are multiple options available depending on the settings you are looking for and not all of them worked for me. I tried setting the environment for the target project on Windows but failed since some of the gems were localized to Linux based environment i.e. would work only for Mac or Ubuntu, etc. So, I installed Ubuntu 12.04 LTS on my machine and started installing rails and guess what roadblocks – some dependencies not met or in conflicted state, make errors, etc….totally bizarre things and ended up in re-installing the OS again (may be due to my limited knowledge of the free platforms). And this how I felt after this!

frustration-baby

Anyway, gathering my composure after a while, I investigated more on the different frameworks etc. I mean this couldn’t be rocket science, right? So, I came across 2 environments – rbenv and rvm. While rbenv didn’t really provide a fruitful result for me, rvm on other hand was much better. And I finally opened the Pandora box.eureka

So, then I thought like a boss and realized how many innocent noobs like me 😉 would have gone thru the same situation and how many more would do the same. So, to save the effort I chalked down a script that would work with minimal customization. The script does the following:

  1. Prepares the OS with the required packages e.g. LAMP, etc.
  2. Installs Ruby using RVM. This script is currently configured to install Ruby version 2.0.0-p247 but of course you can customize it.
  3. Installs the ruby gems (including the Rails framework).

Please see the script is targeted for Ubuntu Linux and is tested on version 12.04 LTS x64. During the span of the script execution your machine should be connected to internet at all times.

To use the script, follow the steps below precisely:

  1. Open the script in an editor and modify rvm lines of code to install your preferred version of ruby. I assume you would know the version of Ruby you would want to install. Please note, you have to modify all the 3 lines of rvm in the script to use the same ruby version. Currently the lines look like this:
    rvm install 2.0.0-p247
    rvm use 2.0.0-p247 --default
    
    
  2. Save your changes and open terminal.
  3. Go to the location where the script file is saved e.g. cd /home/akshaya/
  4. Give executable permissions to the file: chmod uog+rwx RoREnvSetup.sh (name of the script you create)
  5. Execute the script by: sudo ./RoREnvSetup.sh (NO MATTER WHAT DON’T RUN THE SCRIPT AS ROOT USER i.e. DON’T DO “sudo –i” before, unless you are the root user and plan to do all your work as the root user!)
  6. During the installation, it’ll ask prompt you after password you want to set for MySQL DB, etc., please provide it.
  7. Thats it! You have Ruby and Rails installed on your machine.

The RoREvnSetup.sh script is shown below:


sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y

echo "gem: --no-rdoc --no-ri" > ~/.gemrc
echo "export RAILS_ENV=development" >> ~/.bashrc

sudo apt-get install curl -y
\curl -L https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
echo "export rvm_trust_rvmrcs_flag=0" >> /etc/rvmrc
rvm requirements

sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev libc6-dev ncurses-dev automake libtool bison subversion ncurses-term mercurial exuberant-ctags libnotify-bin curl autoconf make ssh openjdk-6-jdk git-doc imagemagick libpq-dev pgadmin3 vim vim-rails vim-gnome lamp-server^ mysql-client libmysqlclient-dev libgdbm-dev libncurses5-dev libffi-dev nodejs -y

rvm install 2.0.0-p247
rvm use 2.0.0-p247 --default
gem update --system
rvm gemset use global
gem update
gem install rails

Advertisements