Tuesday, August 24, 2010

Firing up a new Kubuntu machine for Rails development...

Well... it finally happened.

My Kubuntu machine which I prefer to use for Rails development was getting pretty crochety. I had started out on 7.04, did a distribution upgrade to 8.04, ran into some major problems installing DropBox (LinuxFormat Magazine helped me fix this problem). Finally, I tried a distribution upgrade to 9.10 and it was barely limping along. Several folks suggested a clean install from scratch, so I decided to go with Kubuntu, 10.04, 64-bit.  Here's how I went about it.

Prior to the installation, I took a tar backup of my system and also did a copy (cp -a ...) to an external USB drive. Be careful with cp: if you have other media attached (like another network-attached drive I had a /media/wdhd1), the command "cp -a / /" will follow all those links and try to get EVERYTHING onto the USB drive. I wound up simply copying over the directories that I was most interested in gaining quick access to, such as: /home, /etc, /root, /rails-app. If you've got an old system that you're going to replace, pick the directories that you don't want to lose.

BTW, I really like the NDAS combo drives: eSata, Network-Direct Attached, USB. Reasonably-priced and very effective.
  1. First get Kubuntu (or whatever flavor of Linux distro you want). I went to the Kubuntu site at http://www.kubuntu.org/getkubuntu where you can either download directly or get a CD/DVD. I downloaded the 64-bit desktop version here: http://www.kubuntu.org/getkubuntu/download#download-block
  2. Install kubuntu - pretty straight-forward.
    1. Make sure that your machine will boot from a CD
    2. Insert CD, reboot, follow the instructions.
    3. A true linux sysadmin might have gotten fancy with the disk partitioning, but I just went with the default which was everything in a single partition. It’s not like this is a heavily-loaded server...right?
    4. There were a number of prompts for keeping or replacing existing files (such as mysql/mycnt, /etc/apcupsd/apcupsd.conf, /etc/cups/cupsd.conf, etc...) and I just took the default since I had copies of all my previous config files.
    5. At one point, my mouse went inactive (I connect it through a KVM switch) but that cleared up pretty quickly.
  3. Install your favorite browser by using Kubuntu’s built-in Konqueror browser. I chose Chrome -- I’ve been using Firefox for years, but in the past, I’ve run into problems with Firefox on Linux: older versions, conflicts when trying to upgrade... I still use FireFox on Windows/Mac, but Chrome is my preferred browser for Linux.
  4. The Ubuntu community has a very good site on how to do the Rails install: https://help.ubuntu.com/community/RubyOnRails
    1. Make sure you DO NOT do “sudo apt-get install rails”. This gives you an old version and you can’t track your gems easily. If you mistakenly do that, simply type “sudo apt-get remove rails” and go back to the above link
    2. REMEMBER to add the new ruby gems path to your path so that your system can find the stuff you just installed (this is in the . The command is:
      export PATH=/var/lib/gems/1.8/bin:$PATH”
      You’ll have to add this to your .bashrc file so that it will always be done when you start up.
      1. BTW, I add the following two aliases to my .bashrc so that I can quickly and easily edit .bashrc and update my environment for any new values
        1. alias brcs='source /home/jseidel/.bashrc'
        2. alias brcvi='vi /home/jseidel/.bashrc'
      2. The ‘brcvi’ alias drops me into vi (replace with your preferred editor) so that I can make changes. Notice that it always points to my home directory so that I can do this regardless of where I am.
      3. the ‘brcs’ alias “sources” the current/updated .bashrc file. I.e., it “Reads  and  executes  commands  from .bashrc in the current shell environment”, with the result that the changes you made are reflected in your current bash environment. So to add a new alias, I create the alias in my current bash, test it out, then brcvi to add it to my .bashrc and then brcs to make it active and then test to make sure I didn’ have a typo.
  5. Install git -- you are using git, aren’t you? GitHub has a great tutorial on how to do this. Just go to: http://help.github.com/linux-git-installation/ and follow the instructions. There's also an excellent book, Pro Git, by Scott Chacon, that is available on line at http://progit.org/book/.
  6. Once you’ve installed git, you have to generate an SSH keypair (see http://en.wikipedia.org/wiki/Secure_Shell if you want to learn more about SSH and http://en.wikipedia.org/wiki/Public-key_cryptography if you want to learn more about keypairs) so that you can speak encrypted git.  GitHub has another excellent tutorial on how to do this; see http://help.github.com/linux-key-setup/. Just follow the instructions there and you should have no problem. I did install the xclip utility -- makes it easy to copy/paste the information into github.
    1. If you don’t want to key-in your SSH passphrase everytime you use it, GitHub has help here as well. Go to http://help.github.com/working-with-key-passphrases/ and about half-way down the page there’s a section on “autolaunching ssh-agent” when you start your machine so that you only have to enter the passphrase once when you boot your machine.
    2. Turns out I had some permissions problem in my .ssh directory: I kept getting
            “Bad owner or permissions on /home/jseidel/.ssh/config”
      when testing things with “ssh git@github.com”.  Well, GitHub was there again, with their trouble-shooting page at
      http://help.github.com/troubleshooting-ssh/. Towards the bottom of the page in the “SSH Config” section, the two ‘chmod’ commands did the trick for me.
         chmod 700 ~/.ssh chmod 600 ~/.ssh/*
    3. And don’t forget to setup your git config options -- at least these two
      git config --global user.name "your name"
         git config --global user.email your@email.com
  7. I use RubyMine (http://www.jetbrains.com/ruby/download/index.html#linux for a 30-day free trial) so that was the next thing to install. Replace this section with whatever IDE you prefer: Aptana, NetBeans, ...  
    1. To run RubyMine, you have to have the Sun Java (JDK 1.6). I found that at http://www.oracle.com/technetwork/java/javase/downloads/index.html and followed the instructions. It turned out to be completely straight-forward.
  8. Now you’ve got everything ready to do; let’s create your first rails app in your shiny new Linux development machine:
    rails MyApp
    cd MyApp
    git init
    git commit -m "Empty Rails application"
  9. Now create your github repository -- GitHub has the answer again: http://help.github.com/creating-a-repo/
    1. Once this is done, copy in the repository URL
  10. Back to bash and hooking up your new repository with your new rails app
    1. Tell your local git repository about the github repository:
      git branch add origin
    2. Push your MyApp rails application up to github:
      git push origin master
And you should be good-to-go -- happy rails to you!