Created
January 15, 2024 21:39
-
-
Save gclark-eightfold/f0ab6c20257574b9ccac65e3361c56bd to your computer and use it in GitHub Desktop.
Patch glibc for Node 18+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Upgrades glibc to 2.28 on Ubuntu 18.04 LTS to support Node 18+ | |
# Fixes: node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node) | |
# Original script found here: https://github.com/nodesource/distributions/issues/1392#issuecomment-1815887430 | |
# Check if this patching is needed | |
node -v &>/dev/null | |
if [ $? -eq 0 ]; then | |
echo "Node $(node -v) is installed, and does not require patching." | |
exit 0 | |
fi | |
# Build and install glibc 2.28 if not already installed | |
if [ ! -d "/opt/glibc-2.28" ]; then | |
echo "Installing glibc 2.28..." | |
# Install any missing prerequisites | |
sudo apt-get install -y bison gawk | |
cd ~ | |
wget -c https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz | |
tar -zxf glibc-2.28.tar.gz | |
cd glibc-2.28 | |
mkdir glibc-build | |
cd glibc-build | |
sudo ../configure --prefix=/opt/glibc-2.28 | |
sudo make | |
sudo make install | |
cd .. | |
rm -fr glibc-2.28 glibc-2.28.tar.gz | |
echo "glibc 2.28 installed." | |
else | |
echo "glibc 2.28 is already installed." | |
fi | |
# Patch the installed Node to work with /opt/glibc-2.28 instead: | |
sudo apt install -y patchelf | |
ARCH=$(uname -m) | |
NODE_PATH=$(which node) | |
if [ "$ARCH" = "x86_64" ]; then | |
patchelf --set-interpreter /opt/glibc-2.28/lib/ld-linux-x86-64.so.2 --set-rpath /opt/glibc-2.28/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu $NODE_PATH | |
elif [ "$ARCH" = "aarch64" ]; then | |
patchelf --set-interpreter /opt/glibc-2.28/lib/ld-linux-aarch64.so.1 --set-rpath /opt/glibc-2.28/lib:/lib/aarch64-linux-gnu:/usr/lib/aarch64-linux-gnu $NODE_PATH | |
else | |
echo "Unsupported architecture: $ARCH" | |
exit 1 | |
fi | |
node -v &>/dev/null | |
if [ $? -eq 0 ]; then | |
echo "Node $(node -v) is installed, and has been patched." | |
exit 0 | |
else | |
echo "Failed to patch Node." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment