I installed Db2 LUW 12.1 on Mac (with Apple Silicon) — here is how to do it!
I have been waiting months for this day. When I was told (at PDUG conference) that Db2 12.1 would be released on November 14th, I started counting the days. Today is the big day and I am writing these words while a Db2 12.1 Docker image is being pulled to my M1-based MacBook. I am going to check how does it work.
Db2 LUW is not built for MacOS, therefore on MacBooks You have to run it in a container. Luckily for us, IBM made step-by-step instructions, like this one: Db2 Community Edition for Docker. Db2 Community is a free version for not huge single-node databases without replication (enough for me to test 12.1). Docker is the simplest way to run Db2 on MacOS (here is a link to download Docker on Mac).
Having Docker ready, You can install Db2 according to the following instruction: Installing the Db2 Community Edition Docker image on macOS systems. If You tried to run Db2 11.5 on MacBooks with Apple Silicon, You are probably used to a lot of trial and error and different workarounds. In case of Db2 12.1 it’s works a bit smoother (still, I got stuck twice due to lack of instructions specific to Apple Silicon processors). Namely, the instruction is just copy-pasted from Db2 11.5 Documentation (or was when I was writing these words) and it misses some steps (it was made for Intel-based machines) plus some commands didn’t work for me. Below you can check how I installed Db2 on M-based computer: step-by-step with screenshots and comments, so that You can test it compare it with IBM’s instructions and find your own way.
After I installed and started Docker software, I created Docker folder in my home directory, I tried to pull the db2 image from IBM’s Container Registry (ICR) by executing docker pull icr.io/db2_community/db2:

However it didn’t work: “no matching manifest for linux/arm64/v8 in the manifest list entries”. This is due to my M1 processor. I learned that in such case I had to create the following environment variable: DOCKER_DEFAULT_PLATFORM=linux/amd64. It solved the problem:

Then I changed instance and database names to be created by modifying the .env_list file (it’s optional):

OK, the environment is ready to run the Db2 server. To do so, You need to run the following command:
docker run -it — name db2 -e LICENSE=accept -p 50000:50000 — privileged=true — platform=linux/amd64 icr.io/db2_community/db2 — env-file .env_list
(watch the hyphons while copy-pasting, Medium website merges two ‘-’ into a ‘ — ’ ), where:-i
keeps STDIN open even if not attached,-t
allocates a pseudo-TTY,-e
sets environment variables,-p
specifies the port numbers to use,--privileged
starts the container in privileged mode.

After executing the line above, You have to wait for a while until Db2 is installed, set up and your instance is created (IBM proposes a different command for creating the Db2 server, which didn’t work for me). Finally, You should receive the following message:

The Db2 server is up and running! Notice that after this message I see the diagnostic logs, but I cannot run any more commands there (this behaviour is due to parameters I chose). Therefore the final step to dive into the Db2 12.1 world is to open a new Terminal window and log in to the server, e.g.: docker exec -ti db2 bash -c “su — root” (watch the hyphen type while copy-pasting, there is ‘-’ and ‘ — ’ ):

Great! Let’s create a database, table and run the first SELECT statement:

Now, you can move on to checking the new features. In this IBM’s article we can read that there are +200 new features in 12.1 including the AI-powered query optimizer (only in cloud for now).