Tuesday, December 4, 2012

Guide to install Ruby, Rails, Git, PostgreSQL and Heroku on Ubuntu 12.10

In my opinion there is no better environment to work with RoR than Mac OS X but recently I had to use a PC. After install Ruby, Rails and Git on Windows 8 with RailsInstaller I tried to work but I could not have a decent piece of code. At that time is when I decide to switch to Linux with dual boot to work with RoR. I choose Ubuntu 12.10 (no specific reason, could be other) and this is my personal log with the steps I followed to have my Rails environment on Ubuntu 12.10, just in case I need to do it again.

#Update and upgrade Ubuntu (if needed)
sudo apt-get -y update && sudo apt-get -y upgrade
sudo apt-get install build-essential git-core  #git is needed
sudo apt-get install curl                                #curl is needed
curl -L get.rvm.io | bash -s stable                 #download and install RVM
source /home/johandry/.rvm/scripts/rvm     #execute this or restart your shells
type rvm | head -1                                         #Confirm RVM is installed
#The output should be:
#  rvm is a function
rvm requirements                                         #will display the next command
#requirements for ruby:
sudo 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
rvm list known                                              #List the known rubies
rvm install 1.9.3                                            #Install the latest ruby
rvm use 1.9.3 --default                                  #Set 1.9.3 as the default ruby  
rvm tools rvm-env ruby bash                        #Generate shebang wrappers
gem install rails                                            #Install Rails

The Rails environment is usable now with SQLite but if you want to use Heroku it is recommended to install PostgreSQL because is the DB used.

sudo apt-get install postgresql                      #Install server PostgreSQL
sudo apt-get install pgadmin3                       #PostgreSQL GUI
sudo apt-get install postgresql-client            #Install client PostgreSQL
sudo -u postgres psql postgres                      #Basic setup. Then enter:
\password postgres                                      #to setup the password
#Exit with Ctrl+D
sudo apt-get install libpq-dev                        #Requirement for gem pg
gem install pg                                                #Install gem pg

If you prefer MySQL instead PostgreSQL or SQLite, you may follow these steps but I haven't test them.

sudo apt-get install mysql-client mysql-server libmysql-ruby libmysqlclient-dev
gem install mysql2

To install Heroku execute these steps:

#Install Heroku  Toolbelt
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sudo sh
heroku login                                                   #Login to Heroku
gem install heroku                                          #Install Heroku gem

Now what I need is an editor. For Mac OS X I use Textmate, for Windows I use Notepad++. In Ubuntu I'll use Sublime Text and it may become my preferred editor for Windows or Mac. To install it I execute these commands:

#Download the installer from http://www.sublimetext.com/
tar xf Sublime\ Text\ 2.0.1\ x64.tar.bz2          #Decompress it
mv Sublime\ Text\ 2 sublime                          #Rename it to avoid spaces
sudo mv sublime/ /opt/                                   #Move it to /opt
sudo ln -s /opt/sublime/sublime_text /usr/bin/sublime   #Make it accesible
sudo sublime /usr/share/applications/sublime.desktop #Create a launcher in Unity
#Paste the following code:
[Desktop Entry]
Name=Sublime Text 2
# Only KDE 4 seems to use GenericName, so we reuse the KDE strings.
# From Ubuntu's language-pack-kde-XX-base packages, version 9.04-20090413.
GenericName=Text Editor

[NewWindow Shortcut Group]
Name=New Window
Exec=sublime -n


Post a Comment