Yesterday, I installed nodejs via the Snap store on my Ubuntu 20.04.6 LTS machine. However, when I run the “node” command from my terminal, I get an error:
Here’s how I fixed the issue.
Step 1: Check the location of the libstdc++.so.6
If you look at my error message above, you’ll see that the location where node is looking for libstdc++.so.6 is
/usr/lib/x86_64-linux-gnu/libstdc++.so.6 |
That’s because I didn’t install node in any particular environment (such as a python conda environment). If you installed node inside a conda environment, then try running:
conda install libgcc |
If you’re not running in a conda environment, then go on to the next step.
Step 2: Apt-get update & apt-get upgrade
You might be having this issue because your libstdc++ library is simply out of date. Try running the following commands:
sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade |
Now check if it worked by running:
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX |
If you see GLIBCXX_3.4.30 near the bottom of the list, then you’re done! If not, then continue to the next step.
Step 3: Downgrade Node
It might be that your current OS version is just too old for GLIBCXX_3.4.30. If that’s the case, there are ways around it (such as compiling your own version of libstdc++) but those ways are usually not worth the extra effort or risk to maintain (especially in a production environment). So, the easy solution is to just downgrade Node to an earlier version.
To do this, I first need to uninstall the Node 20.11.1 snap package that I installed earlier:
sudo snap remove –purge node |
Now when I type in the “node” command, I don’t get the errors I got before. Instead, I just get:
bash: /snap/bin/node: No such file or directory |
Perfect. Now I need to figure out which version of Node is compatible with my current version of GLIBCXX. Earlier, I ran the command:
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX |
The latest version of GLIBCXX that displayed in the output was GLIBCXX_3.4.28, so I need a version of Node that is compatible with that.
Searching for “libstdc++” in the nodejs Github org brought me to an issue that mentioned an Ubuntu 20.04.6 machine working with Node 18 but not with Node 20 due to the same error I am having. So I installed Node 18 using the following command:
sudo snap install node –channel=18/stable –classic |
4. Success!
If I run:
node –version |
I no longer get errors. I just get “v18.19.1” as the output.