WSL: WSL Ubuntu 20.04 - gpg: can't connect to the agent: IPC connect call failed

I have a fresh installation of Windows 10, and I am trying to get a development environment with WSL set up. I enabled WSL and installed Ubuntu from the Microsoft Store. Everything went smoothly in that process. Then, I tried to go through the steps to install Yarn here.

When I try to run the first line (curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -), I get the error in the title:

$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
gpg: can't connect to the agent: IPC connect call failed

I have looked up this error, and there were a few suggestions related to gpg-agent that I tried, such as manually starting the agent and creating/deleting certain configuration files related to gpg. Everything I tried resulted in the same error above. I am at a loss for what to try next. Has anyone else seen and fixed this issue?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 73
  • Comments: 72

Most upvoted comments

@onomatopellan in case if build-essential is installed it should be:

sudo add-apt-repository ppa:rafaeldtinoco/lp1871129
sudo apt update
sudo apt install libc6=2.31-0ubuntu8+lp1871129~1 libc6-dev=2.31-0ubuntu8+lp1871129~1 libc-dev-bin=2.31-0ubuntu8+lp1871129~1 -y --allow-downgrades
sudo apt-mark hold libc6

to avoid g++ removal.

But otherwise it works fine, thanks to you and @rafaeldtinoco.

How to fix this issue until Microsoft releases the fix via Windows Update. Solution by @rafaeldtinoco:

sudo add-apt-repository ppa:rafaeldtinoco/lp1871129
sudo apt update
sudo apt install libc6=2.31-0ubuntu8+lp1871129~1 -y
sudo apt-mark hold libc6

Temporary Solution: Downgrade libc6 wget https://launchpad.net/~rafaeldtinoco/+archive/ubuntu/lp1871129/+files/libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb sudo dpkg --install libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb sudo apt-mark hold libc6 #to avoid further update

Edit: /var/lib/dpkg/info/libc6:amd64.postinst and remove the sleep 1 that is in nearly the last line. then try.

Guys, so what do I do if I have 18363 (WSL 1)build only and I need to use gpg? If I use Ubuntu 18.04 instead of 20.04 will it help? Or the only thing is a hack that is described above (by @rafaeldtinoco)

Try installing gnupg1, it works for me 😃

sudo apt-get remove gpg
sudo apt-get install gnupg1

Source: https://github.com/MicrosoftDocs/WSL/issues/662#issuecomment-626680713

I got the same error when a tried to run curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

Guys, so what do I do if I have 18363 (WSL 1)build only and I need to use gpg? If I use Ubuntu 18.04 instead of 20.04 will it help? Or the only thing is a hack that is described above (by @rafaeldtinoco)

Try installing gnupg1, it works for me 😃

sudo apt-get remove gpg
sudo apt-get install gnupg1

Source: MicrosoftDocs/WSL#662 (comment)

This works for me

I resolved it removing the gpg and installing the gnupg1: sudo apt remove gpg sudo apt install gnupg1

sudo apt install libc6=2.31-0ubuntu8+lp1871129~1 libc6-dev=2.31-0ubuntu8+lp1871129~1 libc-dev-bin=2.31-0ubuntu8+lp1871129~1 -y

Will result in:

E: Packages were downgraded and -y was used without --allow-downgrades.

Make sure you add the --allow-downgrades on this step:

sudo apt install libc6=2.31-0ubuntu8+lp1871129~1 libc6-dev=2.31-0ubuntu8+lp1871129~1 libc-dev-bin=2.31-0ubuntu8+lp1871129~1 -y --allow-downgrades

From this command

sudo add-apt-repository ppa:rafaeldtinoco/lp1871129
sudo apt update
sudo apt install libc6=2.31-0ubuntu8+lp1871129~1 libc6-dev=2.31-0ubuntu8+lp1871129~1 libc-dev-bin=2.31-0ubuntu8+lp1871129~1 -y --allow-downgrades
sudo apt-mark hold libc6

What’s happen when Windows release update for this issue and How to rollback when Windows solved this ?

Which Windows build? Ubuntu 20.04 right now is incompatible with WSL1. I just tested in WSL2 and that line runs without problem.

Ubuntu 20.04 sudo apt remove gpg sudo apt install gnupg1

@janba12: https://github.com/microsoft/WSL/issues/5125#issuecomment-631804986 worked for me. You might try this:

sudo apt remove gpg
sudo apt autoremove --purge -y
sudo apt install gnupg1

What’s happen when Windows release update for this issue and How to rollback when Windows solved this ?

sudo apt-mark unhold libc6
sudo apt install ppa-purge
sudo ppa-purge ppa:rafaeldtinoco/lp1871129
sudo apt update
sudo apt upgrade

Hey everyone, enabling WSL 2 works for me.

What I did:

Would love to know which one is the other issue.

Don’t mess up your system by installing / disabling extra programs, just follow the inctructions carefully on micosoft’s website. It takes only 5 minutes to apply.

https://docs.microsoft.com/en-us/windows/wsl/install-win10

It’s a broken libc6 and it’s used everywhere. Try looking for the shared libraries used by a binary: ldd $(which gpg) If you can see libc.so.6 then you probably will hit #4898

Edit: Ok now there is no doubt both issues are related: https://github.com/gpg/gnupg/blob/master/common/sysutils.c#L350

gpg uses nanosleep from glibc which right now is broken in Ubuntu 20.04 WSL1.

I tried this workaround and it did work but I gotta say it seems like a pretty ugly hack. What are the repercussions of holding back libc6? Is there any hope of “cleanup” to where, after installing the needed key and the packages, everything can be put back the way it was?

Guys, so what do I do if I have 18363 (WSL 1)build only and I need to use gpg? If I use Ubuntu 18.04 instead of 20.04 will it help? Or the only thing is a hack that is described above (by @rafaeldtinoco)

Try installing gnupg1, it works for me 😃

sudo apt-get remove gpg
sudo apt-get install gnupg1

Source: MicrosoftDocs/WSL#662 (comment)

Best sollution. Simple. Works for me in Windows build 2004 WSL2 and Ubuntu 20.04

Had the same issue with the kubernetes repo key; I chucked the key in /etc/apt/trusted.gpg.d, it worked and I moved on.

Pretty much seems to be the only solution for you if going with 20.04. The hack does work, tho. Not sure how intricate your particular WSL instance is, but I would figure if it is not that intricate and you need to use gpg, the hack is worth implementing.

Or yeah, you could try 18.04. I believe 18.04 does not have that issue. At least I do not experience on my 18.04 instance.

@onomatopellan in case if build-essential is installed it should be:

sudo add-apt-repository ppa:rafaeldtinoco/lp1871129
sudo apt update
sudo apt install libc6=2.31-0ubuntu8+lp1871129~1 libc6-dev=2.31-0ubuntu8+lp1871129~1 libc-dev-bin=2.31-0ubuntu8+lp1871129~1 -y --allow-downgrades
sudo apt-mark hold libc6

to avoid g++ removal.

But otherwise it works fine, thanks to you and @rafaeldtinoco.

This helped me immensely. I hadn’t struggled for long. Once I saw the issue, I googled and luckily found this. It worked for me as now I’ve been able to install rails.

Don’t mess up your system by installing / disabling extra programs, just follow the inctructions carefully on micosoft’s website. It takes only 5 minutes to apply.

https://docs.microsoft.com/en-us/windows/wsl/install-win10

Works perfectly (and so true btw, just read the docs 😅) while neither other solution worked for me. Thank you so much! 🤘

So here are the commands that saved my day:

wsl --set-default-version 2
wsl --set-version Ubuntu 2
wsl --list --verbose

(last command is for checking that Ubuntu is using WSL2)

How to fix this issue until Microsoft releases the fix via Windows Update. Solution by @rafaeldtinoco:

sudo add-apt-repository ppa:rafaeldtinoco/lp1871129
sudo apt update
sudo apt install libc6=2.31-0ubuntu8+lp1871129~1 -y
sudo apt-mark hold libc6

Worked nice! Thinks.

Just for the record, since that’s the first google finds when searching for the issue: You don’t need to fiddle with your clib or even downgrade to gpg1, the only thing needed to make it work is an environment-Variable, which is best to set by appending these Lines to your shell-Initialisation (~/.bashrc on a default-wsl-ubuntu install):

GPG_TTY=$(tty)
export GPG_TTY

See man gpg-agent in your Linux for an explanation.

EDIT: forgot to say why I still write this, since wsl 2 also fixes the Issue: You can’t use wsl 2 on arm64 devices at the moment, ther seems to be a showstopper for the new release for this architecture. __ s.

The original issue and official response from the WSL team is https://github.com/microsoft/WSL/issues/4898#issuecomment-592196721

Yep, what is it duplicate of?

What’s happen when Windows release update for this issue and How to rollback when Windows solved this ?

sudo apt-mark unhold libc6
sudo apt install ppa-purge
sudo ppa-purge ppa:rafaeldtinoco/lp1871129
sudo apt update
sudo apt upgrade

This screws up libc6 big time. It cannot revert back to pre-rafaeldtinoco changes:

Fetched 5260 kB in 9s (573 kB/s)
Setting up libc6:amd64 (2.31-0ubuntu9) ...
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package libc6:amd64 (--configure):
 installed libc6:amd64 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 libc6:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

To fix this you must do:

sudo rm -rf /var/lib/dpkg/info/libc6*
sudo apt install -f libc6

Guys, so what do I do if I have 18363 (WSL 1)build only and I need to use gpg? If I use Ubuntu 18.04 instead of 20.04 will it help? Or the only thing is a hack that is described above (by @rafaeldtinoco)

For me, WSL2 is a no can do. My dev environment heavily relies on both virtual box and VMware workstation. I know vbox 6 is compatible, but VMware has yet to release their patch…

I have the same issue with WSL 1 and Ubuntu-20.04, converted it into wsl2 wsl

It fails in WSL1 build 19041 and It works in WSL1 build 19613 so I’d say same as #4898.

Can you please run:

$ sudo apt install strace -y

$ strace -o strace.log curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

Then post it to a gist?