Install the Sample DB.

If you created a VM, make sure you are running these steps as the normal user in that VM; not on the host system.

These instructions are for Pop!_OS, they should be similar for Ubuntu.

Check the installation

In Terminal, Run:

su - db2inst1
ksh

You will need to enter the password for db2inst1 after the su command.

Use ksh for a "more useable" command line.

A quick check, Run:

db2 list database directory

returns no DBs.

Validate the install

Run:

cd sqllib/bin

Run:

./db2val

This should return: "The instance validation for the instance db2inst1 was successful."

Install Sample DB

While still in the sqllib/bin directory, Run:

./db2sampl

to create the Sample DB.

Not sure why but this takes a LLLLOOOONNNNGGGG time to complete.

To check success, Run:

db2 list database directory

This should return:

System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = SAMPLE
 Database name                        = SAMPLE
 Local database directory             = /home/db2inst1
 Database release level               = 15.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

Now Run:

db2

This will take you inside DB2 and provide the DB2 prompt.

Then Run:

connect to sample

This will return:

  Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.8.0
 SQL authorization ID   = DB2INST1
 Local database alias   = SAMPLE

Then Run:

select * from employee

This will return a listing of 42 employees

Run:

quit

to exit DB2 and return to the command prompt.

Then Run twice:

exit

to exit the ksh shell and exit db2inst1 and become the "normal" user again.

Install db2profile in .bashrc

As the "normal" user, you will need to run some DB2 commands in Terminal.

To make this possible, add the following 4 lines to the bottom of the .bashrc file which is found in the home directory.

# The following three lines have been added by UDB DB2.
if [ -f /home/db2inst1/sqllib/db2profile ]; then
    . /home/db2inst1/sqllib/db2profile
fi

This will also export some very useful environment variables.

You will need to exit and re-open Terminal for them to be activated.