Install Ruby on Rails on Ubuntu Karmic Koala 9.10

November 8, 2009 · Leave a Comment
Filed under: Featured, Ruby on Rails, Ubuntu 

If you’re running Ubuntu 9.10 and want to install Ruby on Rails I’ve put together a quick tutorial for you. Not tremendously much has changed since the last tutorial for Jaunty Jackalope. Unicorn is out and while I think it’s nifty, I’m going to wait a little while before playing with it. For now my money is still on Phusion Passenger as being the right tool for the job. If all that seems fine, let’s get to the details.

Step 1: As usual, the first thing we’ll want to do is make sure your version of Ubuntu is up to date.:

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

If you see this warning it means we have a little more work to do.

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
 LANGUAGE = (unset),
 LC_ALL = (unset),
 LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Let’s go ahead and set your locale now. (I’m using en-US in this example.. feel free to substitute for your region)

sudo locale-gen en_US.UTF-8
sudo /usr/sbin/update-locale LANG=en_US.UTF-8

Step 2: We’ll be installing some software that needs to be built so we’ll need to get packages required for compiling. With Ubuntu, you can type this single command and get everything you need:

sudo apt-get install build-essential

Step 3: Once you’ve got the tools, it’s time to install MySQL and Ruby. If you’re using SQLite you may not need all this stuff. Otherwise, just copy and paste this command into your terminal if you’re in a hurry. As of Karmic Koala, we’re using MySQL 5.1:

sudo apt-get install ruby ri rdoc mysql-server libmysql-ruby ruby1.8-dev irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15off libnet-daemon-perl libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client-5.1 mysql-common mysql-server-5.1 rdoc1.8 ri1.8 ruby1.8 irb libopenssl-ruby libopenssl-ruby1.8 libhtml-template-perl mysql-server-core-5.1 libmysqlclient16 libreadline5 psmisc

If you hadn’t previously installed MySQL you’ll be asked to set a root password. You don’t have to, of course (it will bug you no fewer than 3 times if you opt not to) but I strongly recommend it. You’ll need this password when you populate your rails config/database.yml file so be sure not to forget it.

Step 4: Grab the latest ruby gems and install them. As always be sure to check rubyforge.org to make sure you’re grabbing the latest one. As of this writing it’s 1.3.5 but it never hurts to confirm.

wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
tar xvzf rubygems-1.3.5.tgz
cd rubygems-1.3.5
sudo ruby setup.rb

Once it’s done you can remove the .tgz file and erase the rubygems-1.3.5 directory too.

Step 5: On the command line, type gem -v. if you get this message we need to make some symlinks:

The program 'gem' can be found in the following packages:
 * rubygems1.8
 * rubygems1.9
Try: sudo apt-get install
-bash: gem: command not found

Let’s create those symlinks now:

sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem
sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

Step 6: Install Ruby on Rails! You can leave off the –no-rdoc and –no-ri switches if you’re on a machine with plenty of ram. But just in case you’ve got a more modest setup (say 256MB or less) I’d just use the following:

sudo gem install rails --no-rdoc --no-ri

If you’re just doing local development then you are basically done. You may want to install additional gems. If you want to deploy Ruby on Rails onto a server then it’s time to setup Nginx and Phusion.

Step 7: As I mentioned earlier, Unicorn may be the new hotness but I’m going to wait a while before I put my customers on that stack. The folks responsible for Phusion Passenger(Hongli Lai & Ninh Bui) are incredibly smart and I think they’ll look at Unicorn and make some improvements to Phusion to eek out even more performance. The short of it is that I’m still a big believer in Phusion so I’m going to install it for production and recommend that you do too:

sudo apt-get install libc6 libpcre3 libpcre3-dev libpcrecpp0 libssl0.9.8 libssl-dev zlib1g zlib1g-dev lsb-base



Step 8: We’re going to create a directory for your application. In anticipation of Capistrano, let’s put it in /var/www/myapp/current. Swap out the myapp with anything you like.

sudo mkdir -p /var/www/myapp/current

If you’ve got an existing Rails application, it doesn’t hurt to populate that directory now. Just make sure that the root to the public directory is /var/www/myapp/current/public. Don’t forget to chown it for www-data:

sudo chown -R www-data:www-data /var/www/myapp/current/

Step 9: Now it’s time to install Phusion Passenger and let it do it’s magic.

sudo gem install passenger
sudo passenger-install-nginx-module

At this point you’ll be greeted with two options. The first will allow Passenger to do all the work while the second, for advanced users, allows you to point Phusion to your pre-installed Nginx. We’re going to make life easy on ourselves and choose option 1. I’d also recommend keeping the default path (/opt/nginx).

The Nginx configuration file (nginx.conf) file is in /opt/nginx/conf/ They’ve done you the favor of adding the lines you need to get going. Defining the configuration file is beyond the scope of this tutorial, but I’ve included a sample file which you can download. This file assumes your application is in /var/www/myapp/current.

Sample nginx.conf file for Ruby on Rails, Nginx, Phusion Passenger.

Step 10: Time to make some Nginx tweaks for Ubuntu/Debian. If you’re used to running nginx as installed by Debian or Ubuntu then you might notice that you’ve lost the familiar way to start and stop nginx. Gone is /etc/init.d/nginx stop and /etc/init.d/nginx/start. To get it back, copy (or download) this into a file called nginx in /etc/init.d/ (as root)

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  reload)
          echo -n "Reloading $DESC configuration: "
          start-stop-daemon --stop --signal HUP --quiet --pidfile     /opt/nginx/logs/$NAME.pid \
              --exec $DAEMON
          echo "$NAME."
          ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
            exit 1
            ;;
    esac

    exit 0

Next, let’s set the permissions and make nginx load on a reboot:

sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

Now you should be able to start and stop nginx using the command you’re used to:

sudo /etc/init.d/nginx start

Bonus steps In case it’s not already installed, let’s grab the perquisites and then install the mysql gem. This will improve performance on your webserver:

sudo apt-get install libmysqlclient-dev
sudo gem install mysql --no-rdoc --no-ri

You should also look into using a helper for deployment. I still use Capistrano but there are alternatives such as Vlad the Deployer, Puppet and others. I will also recommend that if you go with Capistrano that you check out the capistrano-ext gem which allows you to do multi-stage deployments.

Troubleshooting If things didn’t go smoothly, here are some things to check:

1. There’s an error log for nginx in /opt/nginx/logs/ Try looking to see if you get any hints there.

2. If you see a 403 forbidden error, make sure you have permissions set correctly. I’m running Nginx as www-data and I’ve set the group/user owners of my rails app to match using the chown -R www-data:www-data command. It doesn’t hurt to confirm it.

3. Try running your rails app in development mode using the standard script/server. If it doesn’t work there then it obviously won’t work in production mode either

For help, you should check out the great railsforum or Mailing list front-end.

Tor/Privoxy/Karmic Koala

November 7, 2009 · Leave a Comment
Filed under: Featured, Ubuntu 

So the other day I upgraded to Karmic Koala (for the non-techies – thats the new Ubuntu (for those who have no idea what Ubuntu is – I’m proud that I write the only website you ever read) ).  Most of what I needed to work, worked – no problems.  My tablet?  The pen works – the buttons don’t – but so what – I didn’t use them anyway.  It boots quickly, it looks nice, and doesn’t crash.  I’m not sure why they went from a default IM client of Pidgin to Empathy unless its because Empathy has potential.  But its not there yet, so I’m sticking with Pidgin for now.

Now this post isn’t called, Karmic Koala – A Review.  What I wanted to share is how to get Privoxy working with Tor again after the upgrade.  Now if you’re like me when you initially installed Tor, you replaced the Privoxy config file ( /etc/privoxy/config ) with the one from torproject.org .  If you kept this config file during the upgrade, your Privoxy is now broken.  Luckily this is easy to fix.

First, you need to edit /etc/privoxy/config . Look for the 3 lines that look like this:

actionsfile standard  # Internal purpose, recommended
actionsfile default   # Main actions file
actionsfile user      # User customizations

You need to add “.action” to the end of each of these because that is how the files they refer to are named.  So after editing it should look like this:

actionsfile standard.action  # Internal purpose, recommended
actionsfile default.action   # Main actions file
actionsfile user.action      # User customizations

Now you need to edit each of the files named above.  Its a simple search and replace (without quotes): “hide-forwarded-for-headers” with “change-x-forward-for”.

That’s it – Privoxy will now be working again.

How to recover grub2 in Ubuntu 9.10, Karmic Koala

November 1, 2009 · Leave a Comment
Filed under: Featured, Ubuntu 

This is a common problem you will face often. Even thought it was my first encounter with grub2 it wasn’t as simple as I expected. May be its because things are handled a bit differently in grub2 as compared to the old grub. Anyways, in this article I will tell you how to recover grub2 when you have lost it after windows installation, got some error while installing linux or somehow messed it up while changing its configuration. The below is good example.

If you have a live CD, using it boot into a live session and follow the following steps (don’t skip any unless you are know you are doing).

1) Open a terminal (Applications->accessories->terminal) and run this command

[ubuntu]$ sudo fdisk -l

2) The above command will list out the partition table of your hard disk. After identifying your linux installed partition. Run this command, I will use the partition as /dev/sda1 you will have to replace it with yours.

[ubuntu]$ sudo mount /dev/sda1 /mnt

3) If you have /boot on a different partition other then you need to mount it too. After identifying your /boot partition run this command (i am assuming it to be /dev/sda2)

[ubuntu]$ sudo mount /dev/sda2 /mnt/boot

4) Now, mount the rest of the devices

[ubuntu]$ sudo mount –bind /dev /mnt/dev/

5) Now, using chroot we will be allowed to run commands considering a specified root directory.

[ubuntu]$ sudo chroot /mnt

Now, we will be chrooted as root considering /mnt as the root directory. So, from now we won’t need sudo to execute commands as root

6) If you need to make some changes to /etc/default/grub, open the file in your favourite editor ( i will use vim)

[root]$ vi /etc/default/grub

7) Make whatever changes you want to make and run update-grub to create the configuration file.

[root]$ update-grub

8) If you want to install grub2 to MBR run this command.

[root]$ grub-install /dev/sda

If you want to install it to some partition then use that partition name instead of /dev/sda e.g. /dev/sda1 for the second partition etc. Or if you want to install grub2 on another drive then you may use that name e.g. /dev/sdb for an external hard disk.

You will have to resolve the names using fdisk -l command. (be careful while doing that)

9) If you faced some error while installing grub2 then you may want to run it with –recheck attribute.

[root]$ grub-install –recheck /dev/sda

10) Once you are done with this either press Ctrl-D to exit chroot or type exit.

11) And then umount the partition you have mounted starting from /dev

[ubuntu]$ sudo umount /mnt/dev

[ubuntu]$ sudo umount /mnt

Ubuntu Karmic Koala NBR on Asus EEE 901

October 30, 2009 · Leave a Comment
Filed under: Featured, Ubuntu 

The release of Ubuntu Karmic Koala is finally here.

Yesterday I downloaded both the desktop x86 & Netbook Remix ISO’s from the NZ mirror (all up took 10min – sweet bandwidth!) and pretty quickly burnt out the NBR CD and installed it onto the work Asus eee 901. 900mhz Celeron, 1GB ram, 4gb SSD + 16GB SSD.

Karmic works like a treat – everything ‘Just Worked’ – wireless supported (that worked in Linux Mint 7 & Ubuntu NBR 9.04 also), the web camera worked (didn’t in 9.04, but did in Mint with some fiddling), the netbook frontend’s icons work nicely this time as under 9.04 I had to do a kernel hack to get the acceleration out of the video card.

Very nice, very simple install with perfect results.

Well done Ubuntu!

My next attempt with Karmic will be when Mythbuntu release their next version based on 9.10 – can’t wait!

Enable Horizontal Scrolling and Disable Touchpad in Karmic Koala

October 29, 2009 · Leave a Comment
Filed under: Featured, Ubuntu 

Karmic Koala makes it very easy to customize touchpad and therefore makes it more useful. Now you can disable touchpad while typing to avoid your cursor jumping all over the place and/or enable horizontal scrolling with just few clicks. Believe me I’ve tried to disable my touchpad while typing in Jaunty and it involves editing files that’s hard to pronounce. So lucky for all of us, it’s far easier now, no editing (and magic spell) required.

  • go to System -> Preferences -> Mouse
  • then go to touchpad tab,
  • here you can find option to enable horizontal scroll, disable touchpad among other options.

That’s it. It’s more and more human in every release :)

Order your Free Ubuntu 9.10 ( Karmic Koala) CD | Ubuntu Geek

October 16, 2009 · Leave a Comment
Filed under: Featured, Ubuntu 

The next ubuntu stable version is going to be released on 29th October  2009.If you want to order your free CDS use the following link

https://shipit.ubuntu.com/

karmickoala

Ubuntu  9.10 new Features

  • Upstart
  • Boot Experience
  • Software Center
  • GNOME 2.28
  • Application development with Quickly
  • Ubuntu Enterprise Cloud Images
  • Ubuntu One file sharing
  • Linux kernel 2.6.31
  • hal deprecation
  • ext4 by default
  • GRUB 2 by default

And many more for more details on each one check here

« Previous Page