DEV Community

abbazs
abbazs

Posted on • Edited on

How to fix issue "node: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.28' not found (required by node)"?

Why are we facing the "node: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.28' not found (required by node)" issue?

The issue "node: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.28' not found (required by node)" typically occurs when attempting to run Node.js on a system that has an older version of the GNU C Library (GLIBC) installed. Node.js has a dependency on a specific GLIBC version (in this case, version 2.28 or higher), and if the system's GLIBC version is older, it will result in this error.

GLIBC is a crucial library that provides essential functions for programs running on Linux-based systems. Different Linux distributions may have different versions of GLIBC installed by default, and incompatibilities can arise when trying to run software that requires a newer GLIBC version.

This error commonly occurs when using Node.js binaries or packages built with a higher GLIBC version than the one installed on the system. It indicates that the system's GLIBC version needs to be upgraded to meet the requirements of the Node.js version being used.

To address this issue, we can use nvm (Node Version Manager) to manage Node.js versions and ensure compatibility with the required GLIBC version.

What is nvm (Node Version Manager)?

nvm (Node Version Manager) is a command-line utility that allows you to easily manage multiple versions of Node.js on a single machine. It provides a simple way to install, switch, and manage different Node.js versions for different projects.

Here are some key points about nvm:

  1. Version Management: With nvm, you can install and manage multiple versions of Node.js on your system. This is particularly useful when working on projects that require specific Node.js versions, as different projects may have different version requirements.

  2. Easy Version Switching: nvm enables you to switch between installed Node.js versions effortlessly. You can set a specific Node.js version as the default or choose to use different versions for different projects. This flexibility allows you to work with the required version for each project without conflicts.

  3. Project-Level Node.js Configuration: nvm allows you to define a Node.js version for each project or directory. By specifying a .nvmrc file in a project's root directory, you can ensure that the correct Node.js version is automatically selected when you navigate to that project's directory.

  4. Global and Local Package Management: nvm separates the global and local packages for each Node.js version. Global packages are installed separately for each version, ensuring that packages are isolated and compatible with the selected Node.js version.

  5. Community Support: nvm is an open-source project with an active community. It is widely adopted and maintained, ensuring ongoing updates, bug fixes, and new features. The official GitHub repository for nvm provides detailed documentation, installation instructions, and helpful resources.

Using nvm simplifies the management of Node.js versions and allows for a consistent development environment across projects. It ensures that you can easily switch between Node.js versions and avoid conflicts caused by differing version requirements. With nvm, you can seamlessly work on different projects with different Node.js versions, enhancing productivity and maintaining project compatibility.

For more detailed information on nvm, installation instructions, and updates, you can visit the official GitHub repository: https://github.com/nvm-sh/nvm#installing-and-updating

The fix

Note: This solution requires the curl utility. If you don't have curl installed, you can install it using the package manager of your Linux distribution. For Debian-based systems, you can use the following command:

```bash
sudo apt-get update; sudo apt-get install -y curl
```
Enter fullscreen mode Exit fullscreen mode

Now, let's proceed with the steps to fix the GLIBC version issue:

Step 1: Install nvm

  • Run the following command to download and execute the nvm installation script:

    ```bash
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
    ```
    

This will download the installation script and execute it in the current shell session.

Step 2: Configure nvm in .bashrc

  • Check if the necessary configuration lines for nvm are already present in your .bashrc file. The code section below will add the lines if they are not present:

    ```bash
    check=' export NVM_DIR="$HOME/.nvm"'
    if ! grep -qF "$check" ~/.bashrc; then
        echo "" >>~/.bashrc
        echo "# Add NVM to path" >>~/.bashrc
        echo 'export NVM_DIR="$HOME/.nvm"' >>~/.bashrc
        echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >>~/.bashrc
        echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >>~/.bashrc
    fi
    ```
    

Explanation of the code section:

  • The check variable stores the string pattern to check if the configuration lines are already present.
  • The grep command with the -qF option is used to search for the pattern in the .bashrc file without printing anything.
  • If the pattern is not found, the code block inside the if statement is executed.
  • Four lines are appended to the .bashrc file, adding the necessary nvm configuration.

Step 3: Reload .bashrc

  • To apply the changes to the current terminal session, run the following command:

    ```bash
    source ~/.bashrc
    ```
    

This will reload the .bashrc file and make the nvm configuration available.

Step 4: Verify nvm installation

  • Run the following command to verify that nvm is installed and working correctly:

    ```bash
    nvm --version
    ```
    

This should display the version of nvm installed on your system.

You have successfully installed and configured nvm to fix the GLIBC version issue with Node.js on Debian-based Linux.

References:
https://stackoverflow.com/a/73631880/1437877
https://stackoverflow.com/a/47787025/1437877

Top comments (0)