Saturday, July 31, 2010

Install RVM system wide on Ubuntu Server

1: Install git if you don't already have it

$ sudo apt-get install git-core

2: Download RVM

$ sudo bash < <( curl -L http://bit.ly/rvm-install-system-wide )

This creates /usr/local/rvm and the group 'rvm'

3: Add each user to group rvm

$ sudo usermod -aG rvm ubuntu

4: Add startup lines to each user's .profile

[[ -s '/usr/local/lib/rvm' ]] && source '/usr/local/lib/rvm'

5: Add this line to /etc/rvmrc (may not be necessary)

$ echo "export rvm_path=/usr/local/rvm" > /etc/rvmrc

6: Use rvm as a user - best to logout/login first to make sure you get all the paths etc setup

$ rvm list
$ rvm package install zlib ( I needed this to get install to work )
$ rvm install 1.9.2 --with-zlib-dir=/usr/local/rvm/usr

To set default ruby version

$rvm --default use 1.9.2

Thursday, July 22, 2010

RVM with Ubuntu 10.4

1. install ruby lib:


sudo apt-get install curl git-core bison build-essential zlib1g-dev libssl-dev libreadline6-dev libxml2-dev autoconf libxslt1-dev libpq-dev postgresql


2. install rvm

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

3. extra check
mkdir -p ~/.rvm/src/ && cdm ~/.rvm/src && rm -rf ./rvm/ && git clone --depth 1 git://github.com/wayneeseguin/rvm.git && cd rvm && ./install

4. add this line very end of your profile(.bash_profile)

# this is for rvm
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

5. to install ruby 1.9.1

rvm install 1.9.1 ; rvm 1.9.1

Wednesday, April 21, 2010

Install ruby-oci8 on Ubuntu

gzip -dc ruby-oci8-2.0.4.tar.gz | tar xvf -
cd ruby-oci8-2.0.4
make
make install

* When I issue command: sudo make install

luan@luan-laptop:/opt/download/ruby-oci8-2.0.4$ sudo make install
ruby -w setup.rb install
make: ruby: Command not found
make: *** [install] Error 127
luan@luan-laptop:/opt/download/ruby-oci8-2.0.4$ ruby -w setup.rb install
---> lib
mkdir -p /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/
install oci8.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/
Permission denied - /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8.rb
Try 'ruby setup.rb --help' for detailed usage.
luan@luan-laptop:/opt/download/ruby-oci8-2.0.4$ sudo ruby -w setup.rb install
sudo: ruby: command not found
luan@luan-laptop:/opt/download/ruby-oci8-2.0.4$ sudo /opt/ruby/bin/ruby -w setup.rb install
---> lib
mkdir -p /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/
install oci8.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/
---> lib/dbd
mkdir -p /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/dbd
install OCI8.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/dbd
<--- lib/dbd
---> lib/oci8
mkdir -p /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
install oci8.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
install encoding.yml /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
install encoding-init.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
install object.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
install bindtype.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
install datetime.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
install metadata.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
install compat.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
install oracle_version.rb /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/oci8
<--- lib/oci8
<--- lib
---> ext
---> ext/oci8
mkdir -p /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/x86_64-linux/.
install oci8lib_191.so /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/x86_64-linux/.
<--- ext/oci8
<--- ext

----------------------------------------------------------------------------------


I can't install ruby-oci8 on Ubuntu 104 using:

sudo gem install ruby-oci8

luan@luan-laptop:~/app/software/ruby/dev$ sudo /opt/ruby/bin/gem install ruby-oci8
[sudo] password for luan:
Building native extensions. This could take a while...
ERROR: Error installing ruby-oci8:
ERROR: Failed to build gem native extension.

/opt/ruby-1.9.1-p376/bin/ruby extconf.rb
checking for load library path...
LD_LIBRARY_PATH is not set.
checking ld.so.conf... no
checking for cc... ok
checking for gcc... yes
checking for LP64... yes
checking for ruby header... ok
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/ruby-1.9.1-p376/bin/ruby
--with-instant-client
--without-instant-client
/opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4/ext/oci8/oraconf.rb:895:in `get_home': RuntimeError (RuntimeError)
from /opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4/ext/oci8/oraconf.rb:682:in `initialize'
from /opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4/ext/oci8/oraconf.rb:345:in `new'
from /opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4/ext/oci8/oraconf.rb:345:in `get'
from extconf.rb:18:in `
'
---------------------------------------------------
Error Message:
Set the environment variable ORACLE_HOME if Oracle Full Client.
Append the path of Oracle client libraries to LD_LIBRARY_PATH if Oracle Instant Client.

The 'sudo' command unset some environment variables for security reasons.
Pass required varialbes as follows
sudo env LD_LIBRARY_PATH=$LD_LIBRARY_PATH /opt/ruby/bin/gem install ruby-oci8
or
sudo env ORACLE_HOME=$ORACLE_HOME /opt/ruby/bin/gem install ruby-oci8

Backtrace:
/opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4/ext/oci8/oraconf.rb:895:in `get_home'
/opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4/ext/oci8/oraconf.rb:682:in `initialize'
/opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4/ext/oci8/oraconf.rb:345:in `new'
/opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4/ext/oci8/oraconf.rb:345:in `get'
extconf.rb:18:in `
'
---------------------------------------------------
See:
* http://ruby-oci8.rubyforge.org/en/HowToInstall.html
* http://ruby-oci8.rubyforge.org/en/ReportInstallProblem.html



Gem files will remain installed in /opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4 for inspection.
Results logged to /opt/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.4/ext/oci8/gem_make.out

Tuesday, April 20, 2010

Install Oracle 11g R2 on Ubuntu 10.4

I follow the steps from
http://www.pythian.com/news/1355/installing-oracle-11gr1-on-ubuntu-810-intrepid-ibex/

I have to make some adjustments for my Ubuntu 10.4 64 bits, so here are steps:

luan@luan-laptop:~$ sudo su -
[sudo] password for luan:
root@luan-laptop:~# apt-get install gcc make binutils gawk x11-utils rpm alien ksh lsb-rpm
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
(... long list ...)
Suggested packages:
(... another long list ...)
The following NEW packages will be installed:
(... even longer list ...)
0 upgraded, 54 newly installed, 0 to remove and 0 not upgraded.
Need to get 29.3MB of archives.
After this operation, 93.0MB of additional disk space will be used.
Do you want to continue [Y/n]?
Get:1 http://us.archive.ubuntu.com lucid/main gawk 1:3.1.6.dfsg-0ubuntu1 [500kB]
Get:2 http://us.archive.ubuntu.com lucid/main libdrm2 2.3.1-0build1 [260kB]
(...)
Setting up build-essential (11.4) ...
Processing triggers for libc6 ...
ldconfig deferred processing now taking place
root@luan-laptop:~#

root@luan-laptop:~# apt-get install libaio1 lesstif2 libmotif3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libxp6
The following NEW packages will be installed:
lesstif2 libaio1 libmotif3 libxp6
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 1941kB of archives.
After this operation, 4772kB of additional disk space will be used.
Do you want to continue [Y/n]?
Get:1 http://us.archive.ubuntu.com lucid/main libxp6 1:1.0.0.xsf1-2 [16.7kB]
Get:2 http://us.archive.ubuntu.com licid/multiverse libmotif3 2.2.3-2 [1283kB]

root@luan-laptop:~# cd /bin
root@luan-laptop:/bin# ls -l /bin/sh

lrwxrwxrwx 1 root root 4 2010-20-04 21:33 /bin/sh -> dash
root@luan-laptop:/bin# ln -sf /bin/bash /bin/sh
root@luan-laptop:/bin# ls -l /bin/sh

lrwxrwxrwx 1 root root 4 2010-20-04 22:34 /bin/sh -> bash
root@luan-laptop:/bin#
Now create some users:

root@luan-laptop:/bin# cd
root@luan-laptop:~# pwd

/root
root@luan-laptop:~# addgroup oinstall
Adding group `oinstall' (GID 1001) ...
Done.
root@luan-laptop:~# addgroup dba
Adding group `dba' (GID 1002) ...
Done.
root@luan-laptop:~# addgroup nobody
Adding group `nobody' (GID 1003) ...
Done.
root@luan-laptop:~# usermod -g nobody nobody
root@luan-laptop:~# useradd -g oinstall -G dba -p password -d /home/oracle -s /bin/bash oracle
root@luan-laptop:~# mkdir /home/oracle
root@luan-laptop:~# chown -R oracle:dba /home/oracle
root@luan-laptop:~# ln -s /usr/bin/awk /bin/awk
root@luan-laptop:~# ln -s /usr/bin/rpm /bin/rpm
root@luan-laptop:~# ln -s /usr/bin/basename /bin/basename
root@luan-laptop:~# mkdir /etc/rc.d
root@luan-laptop:~# for i in 0 1 2 3 4 5 6 S ; do ln -s /etc/rc$i.d /etc/rc.d/rc$i.d ; done
root@luan-laptop:~# mkdir -p /u01/app/oracle
root@luan-laptop:~# chown -R oracle:dba /u01
root@luan-laptop:~#

Copy the unpacked Oracle 11gR1 to the box we’re working on:


luan@luan-laptop:~$ sudo su -
root@luan-laptop:~# mv /home/download/database /media/database
root@luan-laptop:~# chown -R oracle:oinstall /media/database
root@luan-laptop:~#

Now change some system-wide configuration files, starting with /etc/sysctl.conf:

root@luan-laptop:~# cd /etc
root@luan-laptop:/etc# cp sysctl.conf sysctl.conf.original

Edit it, adding the following lines to the bottom of the file:

fs.file-max = 65535
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 1024 65535
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 262144
Then, let’s modify /etc/security/limits.conf:

root@luan-laptop:/etc# cd /etc/security/
root@luan-laptop:/etc/security# cp limits.conf limits.conf.original

Add the following lines to the bottom of the file:

oracle soft nproc 2047
oracle hard nproc 16383
oracle soft nofile 1023
oracle hard nofile 65535
The last one, for now, is /etc/pam.d/login:

root@luan-laptop:/etc/security# cd /etc/pam.d
root@luan-laptop:/etc/pam.d# cp login login.original

Edit login, adding to it:

session required /lib/security/pam_limits.so
session required pam_limits.so

Here is how to get display working on my laptop.

oracle@luan-laptop:~$ exit
logout
root@luan-laptop:~# DISPLAY=:0; export DISPLAY; xhost +;
access control disabled, clients can connect from any host
root@luan-laptop:~# su - oracle
oracle@luan-laptop:~$ DISPLAY=:0 ; export DISPLAY
oracle@luan-laptop:~$ xclock
oracle@luan-laptop:~$


oracle@luan-laptop:~$ cd /media/database
oracle@luan-laptop:/media/database$ ./runInstaller -ignoreSysPrereqs


Now the windows installation screen will appear. You should be able to follow the default installation.

....

This is a startup script:

root@luan-laptop:/# cat /etc/init.d/oracledb
#!/bin/bash
#
# /etc/init.d/oracledb
#
# Run-level Startup script for the Oracle Listener and Instances
# It relies on the information on /etc/oratab

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_OWNR=oracle
export PATH=$PATH:$ORACLE_HOME/bin

if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi

case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
touch /var/lock/oracle
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
rm -f /var/lock/oracle
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: `basename $0` start|stop|restart|reload"
exit 1
esac

exit 0
root@luan-laptop:/#


root@luan-laptop:/# chmod a+x /etc/init.d/oracledb
root@luan-laptop:/# update-rc.d oracledb defaults 99

update-rc.d: warning: /etc/init.d/oracledb missing LSB information
update-rc.d: see
Adding system startup for /etc/init.d/oracledb ...
/etc/rc0.d/K99oracledb -> ../init.d/oracledb
/etc/rc1.d/K99oracledb -> ../init.d/oracledb
/etc/rc6.d/K99oracledb -> ../init.d/oracledb
/etc/rc2.d/S99oracledb -> ../init.d/oracledb
/etc/rc3.d/S99oracledb -> ../init.d/oracledb
/etc/rc4.d/S99oracledb -> ../init.d/oracledb
/etc/rc5.d/S99oracledb -> ../init.d/oracledb


To startup database:


oracle@luan-laptop:~$ . oraenv
ORACLE_SID = [oracle] ? testdb

The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is /u01/app/oracle
oracle@luan-laptop:~$
oracle@luan-laptop:~$
oracle@luan-laptop:~$ sqlplus '/as sysdba'


SQL*Plus: Release 11.2.0.1.0 Production on Wed Apr 21 09:39:17 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 1269366784 bytes
Fixed Size 2212976 bytes
Variable Size 822086544 bytes
Database Buffers 436207616 bytes
Redo Buffers 8859648 bytes
SQL> alter database mount;

Database altered.

SQL> alter database open;

Database altered.

SQL>

------

How to start Oracle Enterprise Manager


oracle@luan-laptop:~$ emctl start dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved.
https://luan-laptop:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control ............. started.
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/11.2.0/dbhome_1/luan-laptop_testdb/sysman/log
oracle@luan-laptop:~$

Monday, April 19, 2010

Install sys-proctable in Ubuntu 10.04 64 bits

luan@luan-laptop:~$ sudo /opt/ruby/bin/gem install sys-proctable --platform x86-64-linux
Successfully installed sys-proctable-0.9.0-x86-linux
1 gem installed
Installing ri documentation for sys-proctable-0.9.0-x86-linux...
Updating class cache with 3248 classes...
Installing RDoc documentation for sys-proctable-0.9.0-x86-linux...

Thursday, March 25, 2010

Install sqlite3-ruby on Ubuntu 10.4 (for using with sequel)

I got this error while trying install sqlite on Ubuntu 10.4

/opt/ruby-1.9.1-p376/bin/ruby extconf.rb install sqlite3-ruby ruby=/opt/ruby-1.9.1-p376/bin/ruby
checking for fdatasync() in -lrt... yes
checking for sqlite3.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.


1. Install sqlite3

luan@luan-laptop:~$ sudo apt-get install sqlite3


2. Install libsqlite3-dev
luan@luan-laptop:~$ sudo apt-get install libsqlite3-dev

3. Install sqlite3-ruby for using with sequel
luan@luan-laptop:~$ sudo gem install sqlite3-ruby

Monday, February 22, 2010

Can't find tokyocabinet native extention

luan@luan-laptop:~/app/software/ruby/tokyo_projects$ ruby hash_db.rb
hash_db.rb:1:in `require': libtokyocabinet.so.9: cannot open shared object file: No such file or directory - /opt/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/x86_64-linux/tokyocabinet.so (LoadError)
from hash_db.rb:1:in `
'

he solution was to modify the LD_LIBRARY_PATH to include /usr/local/lib or to where the ruby lib is located.


Modified:

sudo vi .bashrc

#~/.bashrc

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

Tuesday, February 9, 2010

install ruby 1.9.1 script

http://gist.github.com/59130

#!/bin/sh

PATCH=376

mkdir -p /usr/local/src && cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p$PATCH.tar.bz2
tar -xjvf ruby-1.9.1-p$PATCH.tar.bz2
cd ruby-1.9.1-p$PATCH
./configure --prefix=/usr --program-suffix=19 --enable-shared
make && make install

install ruby 1.9.1p376 on Ubuntu 9.10

First, remove any ruby version on the system:

sudo apt-get remove --purge ruby1.8 ruby1.9

-- package build dependencies (ruby)

sudo apt-get build-dep ruby1.9

-- get ruby 1.9 source
-- if you can't get it, try to download from
-- http://www.ruby-lang.org/en/

wget -c ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p376.tar.gz

-- extract ruby source using tar

tar -xvzf ruby-1.9.1-p376.tar.gz

-- go to extracted ruby code dir

cd ruby-1.9.1-p376/

-- execute configure
./configure --prefix=/opt/ruby-1.9.1-p376 --enable-shared

-- execute make command
make

-- install process
sudo make install

Then I add the following line to the bottom of $HOME/.bash_profile

luan@luan-desktop:~$ cat .bash_profile
export OC4J_HOME=/opt/oc4j

export JAVA_HOME=/opt/java
export ECLIPSE_HOME=/opt/eclipse
export GROOVY_HOME=/opt/groovy

export GRAILS_HOME=/opt/grails
export TNS_ADMIN=/opt/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export RUBY_HOME=/opt/ruby

export NLS_LANG=AMERICAN_AMERICA.UTF8
export PATH=$ORACLE_HOME/bin:$RUBY_HOME/bin:$JAVA_HOME/bin:$OC4J_HOME/bin:$ECLIPSE_HOME:$GROOVY_HOME/bin:$GRAILS_HOME/bin:$PATH

export AWT_TOOLKIT=MToolkit

Create a link:

luan@luan-desktop:/opt$ ln -s /opt/ruby-1.9.1-p0 /opt/ruby

luan@luan-desktop:/$ cd

luan@luan-desktop:/$ s
ource .bash_profile

luan@luan-desktop:/$ ruby -v
ruby 1.9.1p376 (2009-12-07 revision 26041) [x86_64-linux]


If you are using ruby gem, you need to type:
sudo /opt/ruby/bin/gem