EAI_AGAIN error in bash when using Windows Subsystem for Linux (WSL)

May 5, 2020 | Utkarsh Shigihalli Utkarsh Shigihalli | 1 min read

wsl bash


Lately I am hooked to WSL and have been using bash as my main terminal. It has auto complete, allows me to connect to my Raspberry PI and it just feels nice. However, I recently hit an issue where in I was not able to run any npm commands in zsh shell. Every time I ran any npm command I received error saying getaddrinfo EAI_AGAIN registry.npmjs.org. In this short post, I would like to show how I solved it.

Quick Google search and it was apparent that bash shell was not able to connect to the Internet. Scanning through the results, I found a link to WSL documentation and some common issues list.

Although none were actually resolutions to fix the specific error I was having, I decided to check my DNS setting for the zsh. So I ran cat command and to my surprise DNS entries were not right. Especially it was interesting to see that this (resolv.conf) file is autogenerated, so not sure if it was changed when I switched from bash to zsh.

1
2
3
> cat /etc/resolv.conf
# This file was automatically generated by WSL..
nameserver xxx.xxx.xxx.xxx

I altered the file (after taking backup) with correct DNS entries.

1
> sudo nano /etc/resolv.conf

Save and restarted the WSL, and boom! the npm command was working!

That is it, a quick post on how I solved the EAI_AGAIN error in WSL and a reminder to myself that I should check resolv.conf before blaming npm, oh-my-zsh or the WSL 🙏🏼.


Related Posts
About author
Utkarsh Shigihalli
Utkarsh Shigihalli
Utkarsh is passionate about software development and has experience in the areas of Azure, Azure DevOps, C# and TypeScript. Over the years he has worked as an architect, independent consultant and manager in many countries including India, United States, Netherlands and United Kingdom. He is a Microsoft MVP and has developed numerous extensions for Visual Studio and Azure DevOps.
Comments