0% found this document useful (0 votes)
101 views18 pages

Naresh I Technologies, Hyderabad, 04023746666: C, C++ and Java Programs Compilation On UNIX Environment

This document provides instructions on how to write, compile, and execute programs in C, C++, and Java on Linux. It explains how to write a basic "Hello World" program in each language, check that the required compilers (gcc, g++, javac) are installed, compile the programs, and execute the resulting output files. It also discusses using editors like Vim to write code and interpreting compiler error messages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
101 views18 pages

Naresh I Technologies, Hyderabad, 04023746666: C, C++ and Java Programs Compilation On UNIX Environment

This document provides instructions on how to write, compile, and execute programs in C, C++, and Java on Linux. It explains how to write a basic "Hello World" program in each language, check that the required compilers (gcc, g++, javac) are installed, compile the programs, and execute the resulting output files. It also discusses using editors like Vim to write code and interpreting compiler error messages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 18

Naresh i Technologies, Hyderabad, 04023746666

C, C++ and Java Programs Compilation on UNIX Environment

1. Write a Hello World C Program


Create the helloworld.c program using a Vim editor as shown below.
$ vim helloworld.c
/* Hello World C Program */
#include<stdio.h>
main()
{
printf("Hello World!");
}
2. Make sure C Compiler (gcc) is installed on your system
Make sure gcc is installed on your system as shown below.
$ whereis cc
cc: /usr/bin/cc /usr/share/man/man1/cc.1.gz
$ which cc
/usr/bin/cc
$ dpkg -l | grep gcc
ii gcc 4:4.3.3-1ubuntu1 The GNU C compiler
ii gcc-4.3 4.3.3-5ubuntu4 The GNU C compiler
ii gcc-4.3-base 4.3.3-5ubuntu4 The GNU Compiler Collection (base package)
ii gcc-4.3-doc 4.3.3-5ubuntu4 Documentation for the GNU compilers (gcc, go
ii gcc-4.3-locales 4.3.3-5ubuntu4 The GNU C compiler (native language support
ii gcc-4.3-multilib 4.3.3-5ubuntu4 The GNU C compiler (multilib files)
ii lib64gcc1 1:4.3.3-5ubuntu4 GCC support library (64bit)
ii libgcc1 1:4.3.3-5ubuntu4 GCC support library

3. Compile the helloworld.c Program


Compile the helloworld.c using cc command as shown below. This will create the a.out file.
$ cc helloworld.c
$ ls -l
-rw-r--r-- 1 ramesh ramesh 71 2009-08-28 14:06 helloworld.c
-rwxr-xr-x 1 ramesh ramesh 9152 2009-08-28 14:07 a.out4. Execute the C Program (a.out)
You can either execute the a.out to see the output (or) rename it to some other meaningful name
and execute it as shown below.
$ ./a.out
Hello World!
$ mv a.out helloworld
$ ./helloworld
Hello World!
C++ Programs Compilation
Question: I would like to understand the basics of how to write, compile and execute a C++
program on Linux OS. Can you explain it with a simple example?
Answer: Last week we reviewed how to write C program on Unix OS. In this article, let us
review very quickly how to write a basic Hello World C++ program and how to compile *.cc
program on Linux or Unix OS.
1. Write a Hello World C++ Program
Create the helloworld.cc program using a Vim editor as shown below.
$ vim helloworld.cc

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

// my first program in C++


#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
2. Make sure C++ Compile (g++) is installed on your system
Make sure g++ is installed on your system as shown below.
$ whereis c++
c++: /usr/bin/c++ /usr/include/c++ /usr/share/man/man1/c++.1.gz
$ which c++
/usr/bin/c+
$ dpkg -l | grep g++
ii g++ 4:4.3.3-1ubuntu1 The GNU C++ compiler
ii g++-4.3 4.3.3-5ubuntu4 The GNU C++ compiler
3. Compile the helloworld.cc Program
Compile the helloworld.cc using c++ command as shown below. This will create the a.out file.
$ c++ helloworld.cc
$ ls -l
-rw-r--r-- 1 ramesh ramesh 71 2009-09-03 11:03 helloworld.cc
-rwxr-xr-x 1 ramesh ramesh 9152 2009-09-03 11:06 a.out4. Execute the C++ Program (a.out)
You can either execute the a.out to see the output (or) rename it to some other meaningful name
and execute it as shown below.
$ ./a.out
Hello World!
$ mv a.out helloworld
$ ./helloworld
Hello World!

Java Programming on UNIX


 The Linux Lab
o The Linux lab (do you know any rich person who wants a lab named after
them?) is a collection of Linux (UNIX) workstations in Ungar 426, plus a file
server workstation (in the next room). It belongs to the Department of Computer
Science. This lab provides an up-to-date computing environment to teach
computer science courses.
 Setting up your account
 Command line Computing (the right thing for Computer Scientists)
o Terminal sessions
 Once you have logged into a lab machine, avoid the temptation to start
clicking at things. Really, that's for wimps. Actually, it's OK for starting
applications, but it's not fast enough for real computing.
 Start a terminal session ... the little window thing. When you start a
terminal session you'll be "in" your home directory.

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

 Start another terminal session if you want ... you can have lots of them
running at the same time.
 Now you need to learn some UNIX commands ... the best way is from
your TA during your lab session. Here're a few:
 yppasswd - allows you to change your password
 date - displays the date and time
 ls - lists the files in your current directory
 ls -a - lists all the files, including hidden ones (they start with a .)
 cat - displays a file's contents
 less - displays a file's contents one page at a time
 cp - copies a file
 mv - renames or moves a file
 rm - removes files
 ^D (that's control-D) logs you out of the terminal session
o Directories
 You are probably familiar with the tree-of-directories-and-files most
operating systems impose on the disk space. Gotta love it. In review ...
 There's a place on the harddisk of a machine called lee where you
can store all your files. That's your home directory.
 Whenever you login to a lab machine, it looks like your home
directory is on that machine. Neat, done by NFS.
 You can create subdirectories to organize your files. Windoze
users call subdirectories "folders".
 Terminal session commands for manipulating directories
 mkdir - make a subdirectory
 cd - moves you to another directory (N.B., cd .. moves you to the
parent directory)
 rmdir - remove a subdirectory
 Use the tree to organize your work. For this course you must have the
following directories off your home directory (case sensitive):
 MyPrograms (for your personal programs)
 LabTasks (for your lab tasks)
 Projects (for the two projects)
 Java Program Development
Java program files must end with .java. Create your .java file using an editor, e.g.,
prompt> vi HelloWorld.java
Compile your .java file using javac, e.g.,
prompt> javac HelloWorld.java
If there are no mistakes in HelloWorld.java that will create HelloWorld.class,
which contains the byte-code.
Run your byte-code .class file using java, but omit the .class (weird, and it
shouldn't be, but it is), e.g.,
prompt> java HelloWorld
The output will be on your screen.
 Editing (Java programs)
o nedit (for non-gurus)

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

 Windowing full-featured editor (i.e., will not, in general, run over


network connections)
 Not available everywhere
 The Help menu will get you going
o gvim (for aspiring gurus)
 A graphical version of vim, which may be a good way to get into vim.
o vi/vim (for gurus)
 Plain text editor (i.e., will run over network connections)
 Available on just about any UNIX system
 About 35% of all serious UNIX hackers still prefer vi/vim (or a
derivative)
 vim is just vi improved. In the lab running vi will run vim.
 vimtutor will get you going
o emacs (for gurus with flat noses)
 About 35% of all serious UNIX hackers use Emacs. Also widespread use
on other operating systems
 emacs has zillions of extensions
 Doing ^H t nside emacs will get you going
 javac error messages
o If there are errors in a program submitted to javac then error messages will be
spat out
o The error messages identify the line at which the error was noticed, and provide
clues about the nature of the error.
 The error may be on an earlier line. The compiler works hard to
understand your ravings, and may have to go on past the actual error line
to establish that there really is an error.
 The "clue" is only that. Better you know Java well than rely on those clues
to tell you what's wrong.
o Fixing errors
 Use two terminal sessions, one for compiling and one for editing
 Do a compilation, and if there are errors ...
 Edit to fix at least the first error, and others if you can
 Compile again
o Example: BuggyHelloWorld.java
o Compilation is done in multiple phases, so javac finds all the obvious errors first,
and when you've got them all fixed javac will only then look for subtle errors.
o Generally, fixing one error does not mean less errors the next time you compile.

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

Linux/Unix Installation Instructions of Java


If you have an account on a shared system at a university or an Internet Service Provider,
there's a good chance Java is already installed. Ask your local support staff how to access it.
Otherwise follow these instructions.
The Unix release is a gzipped tar file. You will need about sixty megabytes of free disk space to
uncompress and untar the JDK. Double that would be very helpful. You do this with these
commands:
$ gunzip jdk1_2_2-linux-i386.tar.gz
$ tar xvf jdk1_2_2-linux-i386.tar
The exact filename may be a little different if you're retrieving the release for a different
platform such as Irix or if the version is different.
You can untar it in your home directory, or, if you have root privileges, in some convenient
place like /usr/local/java where all users can have access to the files. However root privileges
are not necessary to install or run Java.
Untarring the file creates all necessary directories and sub-directories. The exact path is
unimportant, but for simplicity's sake this book assumes it's installed it in /usr/local/java. If a
sysop already installed it, this is probably where it lives. (Under Solaris it's also possible the
sysop put it into /opt.) If this is the case the files live in /usr/local/java/jdk1.2.2. If you're
unpacking a different version, then you may find it installed in a slightly different directory
such as /usr/local/java/jdk1.3. This allows multiple versions of the JDK to coexist
harmoniously on the same system. If you unpacked it somewhere other than /usr/local/java,
just replace /usr/local/java by the full path to the java directory in what follows. If you
installed it in your home directory, you can use ~/java instead of a full path.
You now need to add /usr/local/java/jdk1.2.2/bin directory to your PATH environment
variable. You use one of the following commands depending on your shell.
csh, tcsh:
$ set PATH=($PATH /usr/local/java/jdk1.2.2/bin)
sh:
$ PATH=($PATH /usr/local/java/bin); export $PATH
You should also add these lines to the end of your .profile or .cshrc files so you won't have to
repeat them every time you login.
To verify that your Java environment is correctly configured, type "javac nofile.java" at a shell
prompt like this
$ javac nofile.java
If your computer responds with error: Can't read: nofile.java, you're ready to begin. If, on the
other hand, it responds, javac: Command not found or something similar, then you the Java
environment is not properly installed or your PATH is incorrect. You'll need to fix it before
continuing.
Unix/Linux Instructions:
Start the Applet Viewer by doing the following:
From the command line, cd to one of the directories in /usr/local/java/jdk1.2.2/demo, for
example

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

$ cd /usr/local/java/jdk1.2.2/demo/applets/TicTacToe
Run the appletviewer on the file named example1.html:
$ appletviewer example1.html
Play Tic-Tac-Toe! It is allegedly possible to win.

Download or install C, C++ compiler on Red Hat Enterprise Linux 5


A.In order to compile and use c/c++ under Linux you need following packages
=> autoconf : GNU's Autoconf is a tool for configuring source code and Makefiles.
=> make/automake : A GNU tool for controlling the generation of executables and other
non-source files of a program from the program's source files.
=> GNU GCC C compiler (gcc) : The gcc package contains the GNU Compiler Collection
version 4.1
=> GNU GCC C++ compiler (gcc-c++): This package adds C++ support to the GNU Compiler
Collection.

You have total 3 options to download and install GCC compiler under Redhat / CentOS /
Fedora Linux:
[a] Use GUI tool
[b] Install rpm from CDROM/DVD
[c] Download and install compiler from RHN over internet
Option # 1: Use GUI tool
Use GUI tool called system-config-packages to install gcc. Just type the following command and
select gcc and above packages:
$ system-config-packages &
Option # 2: Install rpm from CDROM/DVD
Mount your CD/DVD and install following packages using rpm command.
# rpm -ivh gcc*
Option # 3: Download and install compiler from RHN over internet
You can download and install packages using RHN and yum command:
# yum install gcc gcc-c++ autoconf automake

Short Guide to install Oracle


The following short Guide shows how to install and configure Oracle 9.2.0 on RedHat Linux
7.2 / 8.0 You may download our Scripts to create a database, we suggest this way and NOT

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

using DBASSIST. Besides these scripts, you can download our NET configuration files:
LISTNER.ORA, TNSNAMES.ORA and SQLNET.ORA.
System Requirements
Create Unix Group «dba»
Create Unix User «oracle»
Setup Environment ($HOME/.bash_profile) as follows
Mount the Oracle 9i CD-ROM (only if you have the CD) ...
... or Unpacking downloaded installation files
Install with Installer in interactive mode
Create the Database
Create your own DB-Create Script (optional)
Start Listener
Automatically Start / Stop the Database
Setup Kernel Parameters ( if necessary )
Install Oracle Options (optional)
Download Scripts for RedHat Linux
For our installation, we used the following ORACLE_HOME AND ORACLE_SID, please adjust
these parameters for your own environment.
ORACLE_HOME = /opt/oracle/product/9.2.0
ORACLE_SID = VEN1
System Requirements
Oracle 9i needs Kernel Version 2.4 and glibc 2.2, which is included in RedHat Linux 7.2.
Component
Check with ...
... Output
Liunx Kernel Version 2.4
rpm -q kernel
kernel-2.4.7-10
System Libraries
rpm -q glibc
glibc-2.2.4-19.3
Proc*C/C++
rpm -q gcc
gcc-2.96-98
Create Unix Group «dba»
$ groupadd -g 400 dba
Create Unix User «oracle»
$ useradd -u 400 -c "Oracle Owner" -d /home/oracle \
-g "dba" -m -s /bin/bash oracle
Setup Environment ($HOME/.bash_profile) as follows
# Setup ORACLE environment
ORACLE_HOME=/opt/oracle/product/9.2.0; export ORACLE_HOME
ORACLE_SID=VEN1; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
ORACLE_OWNER=oracle; export ORACLE_OWNER
TNS_ADMIN=/home/oracle/config/9.2.0; export TNS_ADMIN
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1; export NLS_LANG

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data; export ORA_NLS33


CLASSPATH=$ORACLE_HOME/jdbc/lib/classes111.zip
LD_LIBRARY_PATH=$ORACLE_HOME/lib; export LD_LIBRARY_PATH
### see JSDK: export CLASSPATH
# Set up JAVA and JSDK environment:
export JAVA_HOME=/usr/local/jdk
export JSDK_HOME=/usr/local/jsdk
CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JSDK_HOME/lib/jsdk.jar
export CLASSPATH
# Set up the search paths:
PATH=$POSTFIX/bin:$POSTFIX/sbin:$POSTFIX/sendmail
PATH=$PATH:/usr/local/jre/bin:/usr/local/jdk/bin:/bin:/sbin:/usr/bin:/usr/sbin
PATH=$PATH:/usr/local/bin:$ORACLE_HOME/bin:/usr/local/jsdk/bin
PATH=$PATH:/usr/local/sbin:/usr/bin/X11:/usr/X11R6/bin:/root/bin
PATH=$PATH:/usr/local/samba/bin
export PATH
Mount the Oracle 9i CD-ROM (only if you have the CD) ...
Mount the CD-ROM as user root.
$ su root
$ mkdir /cdrom
$ mount -t iso9660 /dev/cdrom /cdrom
$ exit
... or Unpacking downloaded installation files
If you downloaded database installation files from Oracle site (Linux9i_Disk1.cpio.gz,
Linux9i_Disk2.cpio.gz and Linux9i_Disk3.cpio.gz) gunzip them somewhere and you'll get three
.cpio files. The best way to download the huge files is to use the tool GetRight
( http://www.getright.com/ )
$ cd <somewhere>
$ cpio -idmv < Linux9i_Disk1.cpio
$ cpio -idmv < Linux9i_Disk2.cpio
$ cpio -idmv < Linux9i_Disk3.cpio
Now you should have three directories (Disk1, Disk2 and Disk3) containing installation files.
Install with Installer in interactive mode
Install Oracle 9i with Oracle Installer
$ cd Disk1
$ DISPLAY=<Any X-Window Host>:0.0
$ export DISPLAY
$ ./runInstaller
Answer the questions in the Installer, we use the following install directories
Inventory Location: /opt/oracle/product/oraInventory
Oracle Universal Installer in: /opt/oracle/product/oui
Java Runtime Environment in: /opt/oracle/product/jre/1.1.8
Edit the Database Startup Script /etc/oratab
VEN1:/opt/oracle/product/9.2.0:Y
Create the Database
Edit and save the CREATE DATABASE File initVEN1.sql in $ORACLE_HOME/dbs, or create a
symbolic-Link from $ORACLE_HOME/dbs to your Location.

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

$ cd $ORACLE_HOME/dbs
$ ln -s /home/oracle/config/9.2.0/initVEN1.ora initVEN1.ora
$ ls -l
initVEN1.ora -> /home/oracle/config/9.2.0/initVEN1.ora
First start the Instance, just to test your initVEN1.ora file for correct syntax and system
resources.
$ cd /home/oracle/config/9.2.0/
$ sqlplus /nolog
SQL> connect / as sysdba
SQL> startup nomount
SQL> shutdown immediate
Now you can create the database
SQL> @initVEN1.sql
SQL> @shutdown immediate
SQL> startup
Check the Logfile: initVEN1.log
Create your own DB-Create Script (optional)
You can generate your own DB-Create Script using the Tool: $ORACLE_HOME/bin/dbca
Start Listener
$ lsnrctl start LSNRVEN1
Automatically Start / Stop the Database
To start the Database automatically on Boot-Time, create or use our Startup Scripts dbora and
lsnrora (included in ora_config_linux_901.tar.gz), which must be installed in /etc/rc.d/init.d.
Create symbolic Links from the Startup Directories in /etc/rc.d (e.g. /etc/rc.d/rc2.d).
lrwxrwxrwx 1 root root S99dbora -> ../init.d/dbora*
lrwxrwxrwx 1 root root S99lsnrora -> ../init.d/lsnrora*
Setup Kernel Parameters ( if necessary )
Oracle9i uses UNIX resources such as shared memory, swap space, and semaphores extensively
for interprocess communication. If your kernel parameter settings are insufficient for Oracle9i,
you will experience problems during installation and instance startup. The greater the amount
of data you can store in memory, the faster your database will operate. In addition, by
maintaining data in memory, the UNIX kernel reduces disk I/O activity.
Use the ipcs command to obtain a list of the system’s current shared memory and semaphore
segments, and their identification number and owner. You can modify the kernel parameters by
using the /proc file system.
To modify kernel parameters using the /proc file system:
1. Log in as root user.
2. Change to the /proc/sys/kernel directory.
3. Review the current semaphore parameter values in the sem file using the cat or more utility
# cat sem
The output will list, in order, the values for the SEMMSL, SEMMNS, SEMOPM, and SEMMNI
parameters. The following example shows how the output will appear.
250 32000 32 128
In the preceding example, 250 is the value of the SEMMSL parameter, 32000 is the value of the
SEMMNS parameter, 32 is the value of the SEMOPM parameter, and 128 is the value of the
SEMMNI parameter.
4. Modify the parameter values using the following command:

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

# echo SEMMSL_value SEMMNS_value SEMOPM_value SEMMNI_value > sem


In the preceding command, all parameters must be entered in order.
5. Review the current shared memory parameters using the cat or more utility.
# cat shared_memory_parameter
In the preceding example, the shared_memory_parameter is either the SHMMAX or SHMMNI
parameter. The parameter name must be entered in lowercase letters.
6. Modify the shared memory parameter using the echo utility. For example, to modify the
SHMMAX parameter, enter the following:
# echo 2147483648 > shmmax
7. Write a script to initialize these values during system startup and include the script in your
system init files. Refer to the following table to determine if your system shared memory and
semaphore kernel parameters are set high enough for Oracle9i. The parameters in the following
table are the minimum values required to run Oracle9i with a single database instance. You can
put the initialization in the file /etc/rc.d/rc.local
# Setup Kernel Parameters for Oracle 9i
echo 250 32000 100 128 > /proc/sys/kernel/sem
echo 2147483648 > /proc/sys/kernel/shmmax
echo 4096 > /proc/sys/kernel/shmmni

Install Oracle Options (optional)


You may want to install the following Options:
Oracle JVM
Orcale XML
Oracle Spatial
Oracle Ultra Search
Oracle OLAP
Oracle Data Mining
Example Schemas
Run the following script install_options.sh to enable this options in the database. Before
running this scripts adjust the initSID.ora paramaters as follows for the build process. After this,
you can reset the paramters to smaller values.
parallel_automatic_tuning = false
shared_pool_size = 200000000
java_pool_size = 100000000
$ ./install_options.sh
Download Scripts for RedHat Linux
These Scripts can be used as Templates. Please note, that some Parameters like
ORACLE_HOME, ORACLE_SID and PATH must be adjusted on your own Environment.
Besides this, you should check the initSID.ora Parameters for your Database (Size,
Archivelog, ...)
Click here for the download (ora_config_linux_920.tar.gz)
Please visit : http://www.oracle.com/pls/db92/db92....emark=docindex

Installing Oracle9i on RedHat Linux

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

Introduction
This version of Oracle is easier to install than many of the previous ones. However there are still
some traps and issues to get around. if you just need a database with transaction support, get
Postgresql (www.postgresql.org) - it is very easy to install.
Before You Get Oracle
This release recommends 512 Mb of RAM, 1 GB of swap and 3 GB of disk ! You can get away
with 320 MB, 750 Mb and 2.5 Gb respectively - provided you do not attempt to create a database
at install time (wait until later !)
Do not attempt to install at all if you have less than 200 Mb of RAM as the installer will crash at
link time ! (If you are an Oracle install pro then you can link manually to complete the process,
but its a bit of a pest).
This release requires a 2.4.4 Kernel and Glibc 2.2.2. However you can install with 2.4.2 (Redhat
7.1) or 2.4.3 (Mandrake 8.0) Kernels.
There is an undocumented dependency on Binutils. The version that comes with Redhat 7.1
causes Oracle to be unlinkable. The solution is to use the version that comes with Redhat 7.0
(binutils-2.10.0.18) or Mandrake 8.0 (binutils-2.10.1.0.2).
The tested combinations were :
1. Redhat 7.0 with binutils-2.10.0.18
2. Mandrake 8.0 with binutils-2.10.1.0.2.
Getting Oracle
Visit www.oracle.com and click on "Oracle technology Network". The current URL for
downloads is here. Select "9i Database" and then pick the "Linux" entry. You must then agree to
the license before the actual download page appears.
There are three big files :
1. Linux9i_Disk1.cpio.gz (400Mb)
2. Linux9i_Disk2.cpio.gz (620 Mb)
3. Linux9i_Disk3.cpio.gz (80 Mb)
They are actually cpio archives ( not gzipped cpio archives ! ). You need fast internet access...or
a friend with fast internet access.
Once downloaded then expand the archives somewhere where you have 2 GB of space :
# cd /var/bigspace
# cpio -idmv Linux9i_Disk1.cpio.gz
# cpio -idmv Linux9i_Disk2.cpio.gz
# cpio -idmv Linux9i_Disk3.cpio.gz
These expanded archives can be burned to three CDs to provide a convenient and professional
looking installation.
Preparation
Decide where you want Oracle to be installed and create a directory for it ( I use /usr/oracle/
[version] but its up to you). In addition create a group and user for Oracle (login as root for this)
:
# groupadd dba
# useradd oracle
# mkdir /usr/oracle
# mkdir /usr/oracle/9.0
# chown -R oracle:dba /usr/oracle
Remember you need 3 GB or so !
In addition I usually create the file /etc/oratab used to record databases :

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

# touch /etc/oratab
# chown oracle:dba /etc/oratab
There is some folklore about setting a plethora of environment variables and a thing called
"Optimal Flexible Architecture". This business is best summed up by saying : The procedure is
neither optimal, flexible nor an architecture... but a way of laying out files that some Oracle folk
like.
Ensure that you have installed X on your machine, as there is no longer a character mode
installer.
Oracle, like most databases, needs to use IPC to create shared memory. Typically the default
amount configured on most Linux distributions is minimal. To sort this out : ( as root here )
# sysctl -w kernel.shmmax=100000000
# echo "kernel.shmmax = 100000000" >> /etc/sysctl.conf
This enables a shared memory segment to be 100 Mb ( probably enough to start you off...)
Installation
Login as oracle and proceed to install :
$ cd /var/bigspace
$ cd Disk1
$ export ORACLE_HOME=/usr/oracle/9.0
$ ./runInstaller
The Java Gui installer will start and guide you through the process.
This part is now fairly easy - just pick "9i Database", then either of "Enterprise" or "Standard
Edition" depending whether you want all the fancy bits or not ( bitmap indexes, partitions,
transportable tablespaces etc require Enterprise Edition).
The next step asks about what database you want, I usually say "Software Only" and do the
database later.
You will be asked where JDK is... if you don't have a JDK it does not matter ( unless you wish to
do Java development of course).
Then click on install and wait for a while.
At some point you will be asked about the "other locations" for the remaining software
archives.. its fairly straightforward what to be there ( if you have cut CDs, ensure your terminal
window is not still cd'ed into the cdrom mount directory... )
Post Installation
Now comes creating a database. There is a reasonable Gui tool for this :
$ export PATH=$PATH:$ORACLE_HOME/bin
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
$ dbca &
Additionally there is a network configuration tool with a similar UI :
$ netca &
However I will detail a command line creation and configuration of a database so that some
understanding of what is happening can be gained:
Set up configuration for a database called db1 :
$ cat "db1:/usr/oracle/9.0:Y >> /etc/oratab"
$ cd $ORACLE_HOME/dbs
$ cat initdw.ora |sed s/"#db_name = MY_DB_NAME"/"db_name = db1"/|sed
s/#control_files/control_files/ > initdb1.ora
Start and create database :
$ export PATH=$PATH:$ORACLE_HOME/bin

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
$ export ORACLE_SID=db1
$ sqlplus /nolog <<!
connect / as sysdba
startup nomount
create database db1;
!
This creates a default database with files in $ORACLE_HOME/dbs
Now add the database meta data to actually make it useful :
$ sqlplus /nolog <<!
connect / as sysdba
@?/rdbms/admin/catalog
@?/rdbms/admin/catproc
!
Now create a user and give it wide ranging permissions :
$ sqlplus /nolog <<!
connect / as sysdba
create user myuser identified by password;
grant create session,create any table to myuser;
grant unlimited tablespace to myuser;
!
Now the usual sort of database stuff can be done :
$ sqlplus myuser/password <<!
create table mytable(id integer, val varchar2(100));
insert into mytables values(1,'xxxxx');
select * from mytable;
!
You can shut down the database with :
$ sqlplus /nolog <<!
connect / as sysdba
shutdown
!
And start it again with :
$ sqlplus /nolog <<!
connect / as sysdba
startup
!
Simple command line versions of these are provided :
$ dbshut
$ dbstart
The thing that is unusual about Oracle is that there is a one to one correspondence between
database server (ORACLE_SID) and database (db_name in init$ORACLE_SID.ora) - i.e : one
server manages one and only one database. Compare this to Mysql or Postgresql where one
server manages many databases. If you want another database, then you must go through the
above steps again with ORACLE_SID set differently and a new initialization file with a new
db_name in it.

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

Networking
It is nice if remote clients can see your database, so here is the story :
$ echo " LISTENER = (ADDRESS_LIST= (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)
(PORT=1521)) (ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))" >
$ORACLE_HOME/network/admin/listener.ora
$ lnsrctl start
$ echo "DB1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST
= < your host >)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = db1)))" >
$ORACLE_HOME/network/admin/tnsnames.ora
These two commands tell the network listener where to listen, and clients were to send
connection requests to. This can be tested by :
$ tnsping db1 1
This should return (ok) [number]
Housekeeping
It is easy to make Oracle start automatically. Create a script called oracle in /etc/init.d that is
like : ( you need to be root here )
#!/bin/sh
#
# oracle This shell script takes care of starting and stopping
# the oracle services.
#
# chkconfig: 345 90 10
# description: Oracle server
#
# probe: true

# Source function library.


. /etc/rc.d/init.d/functions

# Source networking configuration.


if [ ! -f /etc/sysconfig/network ]; then
exit 0
fi

# Check for echo -n vs echo \c


if echo '\c' | grep -s c > /dev/null 2 > &1 ; then
ECHO_N="echo -n"
ECHO_C=""
else
ECHO_N="echo"
ECHO_C='\c'
fi

# See how we were called.


case "$1" in

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

start)
# Start server.
$ECHO_N "Starting Oracle: "$ECHO_C
su -l oracle -c sqlplus /nolog >/dev/null <<!
connect / as sysdba
startup
!
su -l oracle -c "lsnrctl start > /dev/null"
;;
stop)
# Stop server.
$ECHO_N "Stopping Oracle: "$ECHO_C
su -l oracle -c sqlplus /nolog > /dev/null <<!
connect / as sysdba
shutdown abort
!
su -l oracle -c "lsnrctl stop > /dev/null"
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac

exit 0
Then tell the system to run it : ( as root again )
# chkconfig --add oracle
It is nice to set up the Oracle .bash_profile to get ORACLE_SID and PATH working by default :
# .bash_profile

# Get the aliases and functions


if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

export BASH_ENV=$HOME/.bashrc

export ORAENV_ASK=NO
export ORACLE_SID=db1
if [ -f /usr/local/bin/oraenv ];then
. /usr/local/bin/oraenv
fi
ORAENV_ASK=YES
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
Finally a more sophisticated script to create a database in /var/oradata ( for example ) : ( as
oracle )
#!/bin/bash

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

# ---------------------------------------------------------------------------
# file : createdb1.sql
# ---------------------------------------------------------------------------

DB=db1
DBPATH=/var/oradata
ORACLE_SID=$DB

mkinit()
{
export ORACLE_SID=$DB
export ORAENV_ASK=NO
. /usr/local/bin/oraenv
cp init$DB.ora $ORACLE_HOME/dbs
}

mkdb()
{
sqlplus /nolog <<!
CONNECT / AS SYSDBA
STARTUP NOMOUNT
CREATE DATABASE $DB
DATAFILE '$DBPATH/$DB/sys.dat' SIZE 200M
AUTOEXTEND ON
NEXT 10M
LOGFILE GROUP 1 '$DBPATH/$DB/log01.dat' SIZE 50M,
GROUP 2 '$DBPATH/$DB/log02.dat' SIZE 50M
;
!
}

scdb()
{
sqlplus /nolog <<!
CONNECT / AS SYSDBA
@?/rdbms/admin/catalog
@?/rdbms/admin/catproc
!
}

mktb()
{
sqlplus /nolog <<!
CONNECT / AS SYSDBA
CREATE TABLESPACE rollback
DATAFILE '$DBPATH/$DB/rollback.dat' SIZE 100M
AUTOEXTEND ON

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

NEXT 100M
DEFAULT STORAGE ( INITIAL 10M NEXT 10M PCTINCREASE 0)
;
CREATE TABLESPACE temp
DATAFILE '$DBPATH/$DB/temp.dat' SIZE 100M
AUTOEXTEND ON
NEXT 100M
DEFAULT STORAGE ( INITIAL 10M NEXT 10M PCTINCREASE 0)
TEMPORARY
;
CREATE TABLESPACE data
DATAFILE '$DBPATH/$DB/data.dat' SIZE 200M
AUTOEXTEND ON
NEXT 100M
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO
;
!
}

mkoj()
{
sqlplus /nolog <<!
CONNECT / AS SYSDBA
CREATE ROLLBACK SEGMENt t0 ;
ALTER ROLLBACK SEGMENT t0 ONLINE;
SET TRANSACTION USE ROLLBACK SEGMENT t0;
CREATE ROLLBACK SEGMENT r0 TABLESPACE rollback;
CREATE ROLLBACK SEGMENT r1 TABLESPACE rollback;
ALTER ROLLBACK SEGMENT t0 OFFLINE;
DROP ROLLBACK SEGMENT t0;
!
echo "rollback_segments = (r0,r1)" >> $ORACLE_HOME/dbs/init$DB.ora
}

resp=n
echo -n "Create initial files ?"
read resp
case $resp in
y) echo "Creating initialization files"
mkinit
;;
esac

resp=n
echo -n "Create database ?"

Prepared by Mr. Subba Raju


Naresh i Technologies, Hyderabad, 04023746666

read resp
case $resp in
y) echo "Creating $DB"
mkdb
;;
esac

resp=n
echo -n "Run database scripts ?"
read resp
case $resp in
y) echo "Running scripts for $DB"
scdb
;;
esac

resp=n
echo -n "Create tablespaces ?"
read resp
case $resp in
y) echo "Creating tablespaces for $DB"
mktb
;;
esac

resp=n
echo -n "Create objects ?"
read resp
case $resp in
y) echo "Creating some objects for $DB"
mkoj
;;
esac

Prepared by Mr. Subba Raju

You might also like