Running the x86 IBM i ODBC driver on ARM Linux with Rosetta

ODBC with Db2 for IBM iI recently did some research on how to run the IBM i ODBC driver under Linux on newer macOS architecture and thought I’d share what I learned.

Over the last few years, macOS has changed from x86 (Intel) to ARM architecture. IBM has kept pace by updating its IBM i ODBC driver to support ARM on macOS as of version 1.1.0.15.

Developers who use a Linux virtual machine, however, will note that there is no ARM version of the Linux driver available yet. While an ARM-native version of the driver would be ideal, Mac users running a Linux virtual machine can run the existing x86 version of the driver using Rosetta for Linux.

Prerequisites

Note that you’ll need to run some commands with root privilege; use sudo or log in as root, depending on how your system is set up.

Linux: What’s multiarch?

A multiarch Linux distribution lets you install packages for other architectures. This way, we can have both the ARM and x86 versions of libraries installed. You’ll need this multiarch distribution to run any complex Linux program that depends on x86 shared libraries on an ARM distro. Whole programs can usually be installed, too, but their architecture versions tend to be mutually exclusive.

Note that some distros offer only limited multiarch, if at all. For example, Red Hat–based distributions usually only let you install the 32-bit and 64-bit versions of one type of architecture. In this article, we’ll be using Debian, because Debian (and Ubuntu) have full multi-arch setups.

Setting up Rosetta

Rosetta emulates an x86 environment on newer ARM Macs. The following instructions assume you will set up Rosetta using the open source UTM virtual machine host for Mac with an Apple Virtualization VM. Other virtualization or container software might support Rosetta, but we won’t cover setting up those in this article. Please follow the Rosetta installation instructions in the UTM documentation.

Setting up multiarch (Debian/Ubuntu)

At first, our ARM installation of Debian won’t recognize x86 packages. Let’s add support for 64-bit x86 architecture, also known as amd64:

We’ll need to update the package cache for apt to become aware of this change.

Now, we can install x86 packages.

Install the driver (Debian/Ubuntu)

First, install the driver’s dependencies. We’ll install the x86 version of unixODBC:

Now, we’ll install the driver (filename depending on the version), obtained as described in this blog post by IBM engineer Kevin Adler (Note you want the amd64 version.):

Testing

Because we installed an x86 version of unixODBC, including the isql utility, we can actually test right here. We’ll use the -k flag to pass in a full connection string (though you certainly can use a DSN when set up):

Install an x86 PHP (Debian/Ubuntu)

Because the ODBC driver is x86, PHP needs to be x86 as well.

The PHP provided in Debian 11 does not properly support multiarch, so we recommend Ondřej Surý’s repository, which also provides newer PHP than Debian or Ubuntu. First, follow Surý’s instructions for the Ubuntu PPA or DPA Debian repository, as appropriate, then install PHP:

With a test script…

…we can actually try using x86 PHP:

Using it with Node (Debian)

Using the ODBC driver with node is straightforward because there is a prebuilt x86 version of the ODBC package for Node. Just npm install odbc and make sure you use an x86 version of Node. It’ll pull in a prebuilt version of the Node ODBC package, so there’s no need to install compilers. To install the version of Node from Debian, run this command:

To install from Node upstream, use the x86 version instead of the ARM one.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.