The quickest way to get a working Db2 server is the free Community Edition container image. With Docker installed, this starts Db2 and creates a database named testdb:
docker run -d --name db2server -h db2server \
--privileged=true \
-p 50000:50000 \
-e LICENSE=accept \
-e DB2INST1_PASSWORD='Str0ng#Passw0rd' \
-e DBNAME=testdb \
-v db2data:/database \
icr.io/db2_community/db2
If you need a native install on Windows or Linux instead, the setup wizard steps are further down. Either way, start by picking the edition.
Editions and what the free one allows
Db2 Express-C, the free edition from the Db2 10.5 era, no longer exists. Its replacement is Db2 Community Edition, and the current major release is Db2 12.1. IBM's documentation lists these editions for 12.1:
| Edition | Limits | Production use |
|---|---|---|
| Community | Up to 4 cores and 8 GB of memory per server | No. Non-production only |
| Starter | Up to 4 cores and 16 GB of memory; some features excluded (for example HADR, native encryption, pureScale) | Yes |
| Standard | Up to 16 cores and 128 GB of memory | Yes |
| Advanced | No core or memory limit; all features | Yes |
Two points to check before you rely on Community Edition:
- The non-production restriction is a licence term, not a technical switch. Running a live application on it breaks the licence even though the software will let you.
- The limits changed between releases. Community Edition in Db2 11.5 allowed 16 GB of memory, and some 12.1 pages still quote that figure for the container. Read the edition page for the exact version you install.
Since Db2 11.5 there is one installation image for all editions. It runs as Community Edition until you apply a licence key for a paid edition with db2licm -a.
Option 1: Docker
This works on Linux, on Windows with Docker Desktop, and anywhere else that can run x86-64 Linux containers.
In the docker run command above:
LICENSE=acceptaccepts the licence terms. The container exits without it.DB2INST1_PASSWORDsets the password ofdb2inst1, the instance owner.DBNAMEcreates a database on first start. Leave it out to create databases yourself later.--privileged=trueis required by the image.-v db2data:/databasekeeps the instance and data in a named volume so they survive container removal. On Windows you can bind a folder instead, for example-v C:/db2data:/database.- Port 50000 is the Db2 listener port inside the container.
First start takes several minutes while the instance and database are created. Watch the log and wait for the completion message:
docker logs -f db2server
(*) Setup has completed.
Then open a shell as the instance owner and run a query:
docker exec -ti db2server bash -c "su - db2inst1"
db2 connect to testdb
db2 "SELECT service_level FROM sysibmadm.env_inst_info"
db2 terminate
Applications on the host connect to localhost, port 50000, database testdb, user db2inst1.
To stop and remove everything:
docker stop db2server
docker rm db2server
docker volume rm db2data # deletes the databases
Option 2: Windows setup wizard
Check IBM's system requirements for the Windows versions supported by the release you downloaded before you start. The list is specific and changes between modification packs; if your Windows version is not on it, use the Docker route.
- Sign in with an account in the local Administrators group.
- Download Db2 Community Edition from IBM's Db2 download page (a free IBMid is required) and extract the archive.
- Run
setup.exefrom the extracted folder. The Db2 Setup Launchpad opens. - Choose Install a Product, then Install New under the Db2 server entry.
- Accept the licence agreement.
- Choose the installation type. Typical suits most machines; Custom lets you choose components.
- Choose whether to install, save a response file, or both. A response file lets you repeat the same install unattended on other machines.
- Confirm the installation folder. The default is under
C:\Program Files\IBM\SQLLIB. - Enter the user account that will run the Db2 services. The wizard can create a local account (commonly
db2admin). Use a strong password and record it; Db2 authenticates through the operating system, so this is a real Windows account. - Accept the default instance, named
DB2, or configure its startup and port settings. - Review the summary and click Finish. Files are copied and the instance is created.
The exact panels vary a little between releases, so follow the wizard where it differs from this list.
On Windows the wizard also offers to enable operating system security for Db2 objects, which creates the DB2ADMNS and DB2USERS groups. Users who need to run Db2 commands locally must belong to one of them, and group changes take effect at the next sign-in.
Option 3: Linux
Extract the downloaded archive, check prerequisites, and run the installer as root:
tar -xzf v12.1*_linuxx64_server_dec.tar.gz
cd server_dec
./db2prereqcheck -l
sudo ./db2setup
db2prereqcheck reports missing packages and kernel settings before you start. db2setup launches the same wizard as on Windows when a graphical display is available; on a headless server use a response file (./db2setup -r <file>) or ./db2_install followed by db2icrt to create an instance. The file name of the archive depends on the version you download.
Verify the installation
On Windows, open Db2 Command Window - Administrator from the Start menu. On Linux, switch to the instance owner (su - db2inst1). Then:
db2level
This prints the installed version, fix level and installation path. Next, confirm the instance exists and is running, and create the sample database:
db2ilist
db2start
db2sampl
db2 connect to sample
db2 "SELECT COUNT(*) FROM employee"
db2 terminate
db2start reports SQL1026N The database manager is already active if the instance is already up, which is fine. Check which licence is in effect with:
db2licm -l
To find the port the instance listens on:
db2 get dbm cfg
Look for SVCENAME in the output. It is either a port number or a service name defined in the operating system's services file.
Troubleshooting
db2is not recognised (Windows). You are in an ordinary Command Prompt. Use the Db2 Command Window, or rundb2cmdfirst to initialise the environment.SQL1390C The environment variable DB2INSTANCE is not defined or is invalid. Set it to a name shown bydb2ilist, for exampleset DB2INSTANCE=DB2on Windows orexport DB2INSTANCE=db2inst1on Linux.SQL1032N No start database manager command was issued. The instance is stopped. Rundb2start.SQL30082N Security processing failed with reason "24" (USERNAME AND/OR PASSWORD INVALID). Db2 checks credentials against the operating system. Verify the OS account and password, not a database-level user.- Remote clients cannot connect. Check that
DB2COMMincludes TCP/IP (db2set -all), thatSVCENAMEis set, and that the firewall allows the port. Restart the instance after changing either setting. - The container exits immediately. Read
docker logs db2server. The usual causes are a missingLICENSE=accept, a missing--privilegedflag, or too little memory given to Docker.
Uninstall
On Windows, drop your databases if you no longer need them, then remove the product from Settings > Apps > Installed apps. On Linux, as root, drop the instance with db2idrop <instance> and then run db2_deinstall -a from the install directory under the Db2 installation path.
Further reading
Get the weekly commit
New database deep dives every week.
