2 min read
Upgrading Glibc on Ubuntu 16.04

The minimum version of Glibc required by VSCode Remote Development is 2.28. However, Ubuntu 16.04 comes with Glibc 2.23.

At first, I thought about building Glibc 2.28 from source, installing it alongside the system Glibc in a custom directory, and using patchelf to modify the related binaries to use the custom Glibc.

But this approach seemed too complicated and inconvenient. I didn’t want to repeat the process every time I created a new container.

So, I decided to upgrade the system Glibc to 2.28.

Here are the key points:

  • Make sure the configure parameters are the same as the system Glibc.
  • After compiling, don’t install it directly. Instead, use make install with the DESTDIR set to another directory such as /rootfs.
  • Use Docker’s multi-stage build to copy the new Glibc to the Ubuntu 16.04 image.
  • Install a statically linked bash before the copy stage, and run ldconfig after the copy stage (because the generated ld.so.cache only contains the new Glibc’s libraries. Other libraries will fail to resolve if they are not in LD_LIBRARY_PATH or the default library path, or if they are in the default library path but were linked with the -z nodefaultlib linker option).