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: https://bitbucket.org/ged/ruby-pg/wiki/Home
My Previous Installation (on Ubuntu 10.10): http://socrateos.blogspot.com/2011/05/installing-pg-on-ubuntu-again.html
My First Installation: http://socrateos.blogspot.com/2010/08/sudo-gem1.html


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
RubyGems.org: http://rubygems.org/gems/qtbindings
QtBindings Homepage: https://github.com/ryanmelt/qtbindings
Qt Homepage: http://qt.nokia.com/
My Previous Installation (Ubuntu 10.10): http://socrateos.blogspot.com/2011/05/installing-qtbindings.html
My Installation on Windows: http://socrateos.blogspot.com/2011/06/installing-qtbindings-alt-qt-ruby-on.html

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-4.6.3.2
1 gem installed
Installing ri documentation for qtbindings-4.6.3.2...
Installing RDoc documentation for qtbindings-4.6.3.2...

4. Test
$ irb
irb(main):001:0> require 'Qt'
=> true
irb(main):002:0> a = Qt::Application.new(ARGV)
=> #<Qt::Application:0x97f20ac objectName="irb">
irb(main):003:0> button = Qt::PushButton.new('Hello World!',nil)
=> #<Qt::PushButton:0x97d199c objectName="", x=0, y=0, width=640, height=480>
irb(main):004:0> button.resize 300, 30
=> nil
irb(main):005:0> button.show
=> 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: http://code.google.com/p/ps3mediaserver/
My Previous Installation (Ubuntu 10.10): http://socrateos.blogspot.com/2011/01/1.html
A step-by-step instruction: http://irrationale.com/2010/06/30/ps3-media-server-on-ubuntu-10-04/

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 (http://socrateos.blogspot.com/2011/01/1.html) 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 PMS.sh
$ sudo chmod +x linux/tsMuxeR

5. Launch

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


6.Configuration

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;./PMS.sh"
Note that I cd to the directory where PMS.sh 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]
Perfect!

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
1.3.7
$ 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: https://launchpad.net/~pitti/+archive/postgresql

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/logrotate.d/postgresql-common
/etc/postgresql/9.0
/etc/postgresql/9.0/main                    # directory for config files
/etc/postgresql/9.0/main/environment
/etc/postgresql/9.0/main/pg_ctl.conf
/etc/postgresql/9.0/main/pg_hba.conf
/etc/postgresql/9.0/main/pg_ident.conf
/etc/postgresql/9.0/main/postgresql.conf
/etc/postgresql/9.0/main/start.conf
...
/usr/lib/postgresql                          # server apps
/usr/lib/postgresql/9.0
/usr/lib/postgresql/9.0/bin
/usr/lib/postgresql/9.0/lib
...
/var/lib/postgresql                          # home directory for root user postgres
/var/lib/postgresql/9.0
/var/lib/postgresql/9.0/main                 # I will create error log directory (pg_log) here
/var/lib/update-rc.d/postgresql
/var/log/postgresql
/var/log/postgresql/postgresql-9.0-main.log
/var/log/postgresql/postgresql-9.0-main.log.1
...

$ 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 
ALTER ROLE
postgres=# \q            # quit psql
$ exit                   # exit from user 'postgres'
exit


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       127.0.0.1/32       trust          # md5 -> trust

Make changes to postgresql.conf for error log.
#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------
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
postgresql-2011-07-23_135126.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.