Wednesday, 2 November 2016

Oracle Database installation on Ubuntu 16.04

Hello folks, hope you are all well.

Some days ago, on Quora, I answered a question on OS options. I wrote some points on Ubuntu, Windows, Open SUSE and Oracle Linux. I am using Ubuntu for quite a sometime and I am happy with it. So, my answer also pointed the same.

While this discussion was going on, some fellow developers asked me about the installation procedures of some software applications. I thought of writing one by one in this area. Let's start with Oracle Database.

Well, sometimes, installing and configuring Oracle Database server on ubuntu is very difficult. I failed sometimes. But, here is the one I got success. Let's go one step at a time.

Step 1 - Configure your Ubuntu

To install Oracle Database, you will need the following packages and also need some system configuration. Let's perform these administrative tasks first.

  1. The installer comes in Redhat Package format, to convert it to Debian Package we need some packages. Let's start with installing the required packages.
    sudo apt-get install alien libaio1 unixodbc
  2. Now its time for a little background, the installer relies on the redhat system configurations. So, you also need to provide the similar to the installer to be successful. Basically, we'll add two files, one for configuration check and another for kernel parameter settings.
  3. Starting with the Configuration file. Create a file with the following command
    sudo vi /sbin/chkconfig
    

    Now paste the following in that file and save it
    #!/bin/bash
    
    file=/etc/init.d/oracle-xe
    if [[ ! `tail -n1 $file | grep INIT` ]]; then
        echo >> $file
        echo '### BEGIN INIT INFO' >> $file
        echo '# Provides: OracleXE' >> $file
        echo '# Required-Start: $remote_fs $syslog' >> $file
        echo '# Required-Stop: $remote_fs $syslog' >> $file
        echo '# Default-Start: 2 3 4 5' >> $file
        echo '# Default-Stop: 0 1 6' >> $file
        echo '# Short-Description: Oracle 11g Express Edition' >> $file
        echo '### END INIT INFO' >> $file
    fi
    update-rc.d oracle-xe defaults 80 01
    
  4. The next file is to set the kernel parameters. Create another file with the following command,
    sudo vi /etc/sysctl.d/60-oracle.conf
    

    Now paste the following content in the file and save it,
    # Kernel parameters 
    fs.file-max=6815744  
    net.ipv4.ip_local_port_range=9000 65000  
    kernel.sem=250 32000 100 128 
    kernel.shmmax=536870912 
    
  5. Once done with the configurations, set the file access properties with the following commands,
    sudo chmod 0755 /sbin/chkconfig
    
    sudo chmod 0755 /etc/sysctl.d/60-oracle.conf 
    
  6. Now load the kernel parameters with the following command
    sudo service procps start

Step 2 - Install Oracle JDK

Installing Oracle Java is quite simple, just run the following steps and you will get success,
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

While, this is true that, getting Oracle Java is easy, the tricky part is to manage the JDK, you want to use. While installing Oracle Database Oracle JDK is must, if you are running any other JDK, installation may fail. I have quite a tough time dealing with this situation.

Well, to achieve this, you need to type in the following commands,

palash@palash:~$ sudo update-alternatives --config java
[sudo] password for palash: 
There is 1 choice for the alternative java (providing /usr/bin/java).

  Selection    Path                                     Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java   1081      auto mode
* 1            /usr/lib/jvm/java-8-oracle/jre/bin/java   1081      manual mode

Press <enter> to keep the current choice[*], or type selection number: 
palash@palash:~$ sudo update-alternatives --config javac
There is 1 choice for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                  Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/bin/javac   1081      auto mode
* 1            /usr/lib/jvm/java-8-oracle/bin/javac   1081      manual mode

Press <enter> to keep the current choice[*], or type selection number: 

Now, you can see, I have only Oracle Java Installed,so I do not have any problem. If you have OpenJDK as well, you might have to change the default value to Oracle Java.

In my case, I simply pressed <Enter> but you may have to key in some other Selection depending on your installed JDKs.

Step 3 - Download the Oracle Database Installer

Once you have changed your default JDK to Oracle JDK, you now need to download the Oracle Database Installer.
  1. Navigate to Oracle Database Installer Download page.
  2. Accept the License Agreement
  3. Click on the download link for Oracle Database Express Edition 11g Release 2 for Linux x64
  4. Get yourself some coffe, it will take some time to download.

Step 4 - Installation

Once your system is configure, you have Oracle JDK as default and you have the Installer ready, you can look forward to install the database.
  1. Copy the installer in your favourite directory. I have moved to $HOME/Softwares directory.
  2. Change the directory to the directory of previous step
  3. Now, unzip the installer with the following command,
    unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip 
    
  4. Once unzipped, you need to move to Disk1 Directory
    cd Disk1/
  5. Once you are in Disk1 directory, you can find a file with extension .rpm. You need to convert it to Debian package format. To do this, run the following command,
    sudo alien --scripts -d oracle-xe-11.2.0-1.0.x86_64.rpm
  6. Once all these are done, run the following command and it will install the database. The file name might differ in your case, so be careful
    sudo dpkg --install oracle-xe_11.2.0-2_amd64.deb
  7. Once the installation is done, configure the database with System password and all the details and enjoy working with  Oracle Database on your Ubuntu Linux.
    sudo /etc/init.d/oracle-xe configure 

Step 5 - Starting, Stopping, Restarting

Congratulations, you have successfully installed Oracle Database and you are quite enthusiastic at this point to start the database, here are some commands to help you start,
sudo service oracle-xe start
sudo service oracle-xe stop
sudo service oracle-xe restart
For other configuration and other oracle service related services, check with
sudo service oracle-xe
That's all folks...

No comments:

Post a Comment