Friday, July 8, 2011

Installing pg (ruby-pg) on Ubuntu (11.04)

I installed pg (ruby-pg) on Ubuntu 11.04.

1. Resources
Home Page:
My Previous Installation (on Ubuntu 10.10):
My First Installation:

2. Requirements
libpgsql-ruby (installed 1.9.1 version, using Synaptic)
postgresql-server-dev (installed 9.0 version, using Synaptic)

3. Installation
$ sudo gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...

4. Test
$ irb
irb(main):001:0>; require 'pg'
=> true

Installing qtbindings on Ubuntu (11.04)

I installed qtbindings on my Ubuntu 11.04.

1. Resources
QtBindings Homepage:
Qt Homepage:
My Previous Installation (Ubuntu 10.10):
My Installation on Windows:

2. Requirements
Qt 4.6.x -- already installed (via installation of Qt Creator)
cmake 2.6.3+ -- I used Synaptic to install (2.8.3)
gcc 4.x -- already installed
Ruby -- already installed (Installing Ruby 1.9.2 on Ubuntu (11.04))

3. Installation
WARNING: This takes really long time. It took over 5 min for me.
$ sudo gem install qtbindings
Building native extensions.  This could take a while...  # get some coffee
Successfully installed qtbindings-
1 gem installed
Installing ri documentation for qtbindings-
Installing RDoc documentation for qtbindings-

4. Test
$ irb
irb(main):001:0> require 'Qt'
=> true
irb(main):002:0> a =
=> #<Qt::Application:0x97f20ac objectName="irb">
irb(main):003:0> button ='Hello World!',nil)
=> #<Qt::PushButton:0x97d199c objectName="", x=0, y=0, width=640, height=480>
irb(main):004:0> button.resize 300, 30
=> nil
=> nil
irb(main):006:0> a.exec
=> true

5. Result

Installing Qt4 on Ubuntu (11.04)

Installation of Qt4 on Ubuntu (11.04) is simple because it is available in Ubuntu Software Center.

1. Go to Main Menu > Ubuntu Software Center > Development > IDE
2. Find and install Qt Creator.

Qt Creator includes everything I need, including Qt4 4.7.2 and Qt Designer.

Wednesday, July 6, 2011

Installing PS3 Media Server on Ubuntu 11.04

I am re-installing everything after I upgraded my Ubuntu to 11.04 with a clean install. PS3 Media Server is one of software packages to reinstall.

1. Resources

PS3 Media Server Homepage:
My Previous Installation (Ubuntu 10.10):
A step-by-step instruction:

2. Preparations

PS3 Medea Server requires: sun-java6-jre, mplayer, mencoder,and ffmpeg.

I use Synapitc for package installation when possible, and these packages are all available from Synaptic. However, sun-jav6-jre is not available in the default repository of Ubuntu 11.04. You have to enable Canonical Partners repositories first before installing it. To do this, launch Synoptic. Goto the Settings menu and select Repositories option. Then goto the Other Software tab. Enable Canonical Partners. Then click the Refresh button to refresh the list of packages. Now search and install all these packages from Synaptic.

3. Download (or not)

I decided to use older version of PS3 Media Server (pms-generic-linux-unix-1.20.412.tgz) instead of downloading the latest version (pms-generic-linux-unix-1.25.1.tgz). The reasons were that I had a little problem with the newer version when I upgraded to it in my previous Ubuntu (10.10) and that I did not have any issue with the older version (1.20.412). Although I could not find a way to download an older version, I had a copy this older version in my download folder.

4. Installation

The installation process was basically same as before ( except that I did not edit PMS.conf file. I used its default settings (and it worked).

mv ~/pms-linux-1.20.412/ /opt/pms 
$ cd /opt/pms
$ sudo chmod +x
$ sudo chmod +x linux/tsMuxeR

5. Launch

Launch the server
$ cd /opt/pms
$ ./


Added my Video and Photo folders for streaming.

7.Adding to Main Menu

Since I do not run PS3 Media Server all the time, I do not like to run it as a daemon. But I do not like to execute it from a command line either. So I created a Ruby script to call from the Main Menu.

This is my simple Ruby script that execute a script (pms.rb) that launch the Media Server.
#!/usr/bin/env ruby
# pms.rb
# Launch PS3 MediaPlayer Server

system "cd /opt/pms;./"
Note that I cd to the directory where script is before executing it. Otherwise, PS3 Media Server does not run correctly.

Make it executable.
$ sudo chmod 755 pms.rb

Then I put it in the Main Menu Bar.
(a) Preference Menu > Main Menu
(b) Select "Sound and Video" category.
(c) "New Item" button
(d) Give it a Menu Item Name: "PS3 Media Server"
(e) Specify location of the Ruby script.
Now I can start the Media Serve at anytime easily.

It's been working great.

Tuesday, July 5, 2011

Installing Ruby 1.9.2 on Ubuntu (11.04) as its Default Ruby without RVM

I have recently upgraded my Ubuntu to 11.04 with a clean install. So I had to reinstall Ruby all over again. This time I wanted to install Ruby 1.9.x instead of 1.8.7 as its default (system) Ruby.

RVM (Ruby Version Manager) is a recommended tool to install Ruby, but I think I have to have a Ruby installed already before even installing RVM, which is a Ruby gem. This is my initial (pre-RVM) Ruby installation.

Besides, I do not know yet a simple way to use an RVM-installed Ruby when I want to run it without logging in and without launching bash shell - running as a daemon. So I really wanted to install 1.9.x version of Ruby as my default (system) Ruby.

Ubuntu has two versions of Ruby in its repository: 1.8.7 and 1.9.1. So I installed 1.9.1 using Synaptic. To my surprise, it installed 1.9.2!.

$ ruby1.9.1 -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Now I do not like to call ruby like
$ ruby1.9.1 myapp.rb
So I just created a symlink.
$ sudo ln -s /usr/bin/ruby1.9.1 /usr/bin/ruby
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

I did the same thing for gem1.9.1 and irb1.9.1.
$ sudo ln -s /usr/bin/gem1.9.1 /usr/bin/gem 
$ sudo ln -s /usr/bin/irb1.9.1 /usr/bin/irb
$ gem -v
$ irb -v
irb 0.9.6(09/06/30)
$ irb
irb(main):001:0> RUBY_VERSION
=> "1.9.2"

[New] Finally, I added /var/lib/gems/1.9.1/bin to the PATH so that gems can be accessible as commands. I added the following line at the end of my .bashrc.
export PATH=/var/lib/gems/1.9.1/bin:$PATH

I have now the latest Ruby and irb as my default (system) Ruby in the latest Ubuntu.

Monday, July 4, 2011

Installing PostgreSQL 9.0 on Ubuntu (11.04) using PPA

The version of default PostgreSQL in the latest Ubuntu (11.04) is still 8.4.8.
So I decided to install 9.0 version when I found there is a PPA (Personal Package Archives) for it. (I have no previous version of PostgreSQL in this Ubuntu PC.)

1. Resources.
PostgreSQL PPA:

2. Add PPA repository to my Ubuntu.
$ sudo add-apt-repository ppa:pitti/postgresql

3. Install PostgreSQL 9.0
$ sudo apt-get update
$ sudo apt-get install postgresql

4. Check the installation [updated 2011-07-24]
$ locate postgresql  # check the locations of postgresql files
/etc/init.d/postgresql                      # server daemon
/etc/postgresql/9.0/main                    # directory for config files
/usr/lib/postgresql                          # server apps
/var/lib/postgresql                          # home directory for root user postgres
/var/lib/postgresql/9.0/main                 # I will create error log directory (pg_log) here

$ psql -V             # check psql version
psql (PostgreSQL) 9.0.4

$ finger postgres     # check if user postgres is created
Login: postgres          Name: PostgreSQL administrator
Directory: /var/lib/postgresql       Shell: /bin/bash
Never logged in.
No mail.
No Plan.

$ su postgres          # switch user to postgres
$ psql                 # launch psql as postgres and check the server version
psql (9.0.4)

postgres=# select version();
 PostgreSQL 9.0.4 on i686-pc-linux-gnu, compiled by GCC gcc-4.5.real (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2, 32-bit

5. Setup Root User 'posrgres'
The installer has created a unix user postgres without a password. So first I give a (unix) password to this special user. The user postgress is a root user (database administrator) of PostgreSQL Server but without a (PostgreSQL) password. So I give it one here as well.
$ sudo passwd postgres # give the postgres user a (unix) password
$ su postgres           # switch to the user postgres
$ psql                   # launch psql to give postgres PostgreSQL passord
postgres=# alter user postgres with password 'secret';  # new password for postgres 
postgres=# \q            # quit psql
$ exit                   # exit from user 'postgres'

6.Configure PostgreSQL Server
I want to make some changes to server config.

Make backup copies of config files.
$ su postgres    # switch to the user postgres
$ cd /etc/postgresql/9.0/main
$ ls -la
-rw-r----- 1 postgres postgres  4108 2011-07-02 19:54 pg_hba.conf
-rw-r--r-- 1 postgres postgres 18064 2011-07-02 19:54 postgresql.conf

postgres@ubuntu-pc:/etc/postgresql/9.0/main$ cp pg_hba.conf pg_hba.conf.bak.original 
postgres@ubuntu-pc:/etc/postgresql/9.0/main$ cp postgresql.conf postgresql.conf.bak.original 

postgres@ubuntu-pc:/etc/postgresql/9.0/main$ ls -la
-rw-r----- 1 postgres postgres  4108 2011-07-02 19:54 pg_hba.conf
-rw-r----- 1 postgres postgres  4108 2011-07-03 18:33 pg_hba.conf.bak.original
-rw-r--r-- 1 postgres postgres 18064 2011-07-02 19:54 postgresql.conf
-rw-r--r-- 1 postgres postgres 18064 2011-07-03 18:33 postgresql.conf.bak.original

Make changes to pg_hba.config (authetification methods).
host    all         all       trust          # md5 -> trust

Make changes to postgresql.conf for error log.
log_destination = 'stderr'  # 2011.07.04 - enabled
logging_collector = on   # 2011.07.04 - enabled and turned on
log_directory = 'pg_log'  # 2011.07.04 - enabled. I will create this folder (see below).
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # 2011.07.04 - enabled
log_truncate_on_rotation = off  # 2011.07.04 - enabled and keep it off
log_rotation_age = 1d   # 2011.07.04 - enabled
log_rotation_size = 10MB  # 2011.07.04 - enabled

Create a log directory as specified in the config above.[updated on 2011-07-24]
$ su postgres         # switch to postgres user
$ cd ~/9.0/main/      # /var/postgresql/9.0/main
$ mkdir pg_log        # create a new log directory as specified in the config file above
$ ls -F               # confirm the new directory 'pg_log'
PG_VERSION  pg_log/ ...
$ exit

7. Restart the server [new]
I have to restart the server to use new configurations.
$ sudo /etc/init.d/postgresql restart
 * Restarting PostgreSQL 9.0 database server  
$ sudo /etc/init.d/postgresql status
Running clusters: 9.0/main 

8. Check the new log. [new]
Now I should have a new log generated.
$ sudo ls /var/lib/postgresql/9.0/main/pg_log

9. Finally Install pgAdmin III (GUI tool for PostgreSQL) [new]
Since the same PPA repository (ppa:pitti/postgresql) also contains the latest pgAdmin III, I can install it with a simple apt-get command.
$ sudo apt-get install pgadmin3   # install the latest pgAdminIII
$ pgadmin3                        # launch it
It is version 1.12.2.