Can't install cuda on wsl2. "The public CUDA GPG key does not appear to be installed."

I follow the installation guide of cuda on wsl2. I’ve tried both options but I get similar error:

simon@LAPTOP-1DR6GGES:~$ sudo dpkg -i cuda-repo-wsl-ubuntu-11-7-local_11.7.0-1_amd64.deb
(Reading database ... 44224 files and directories currently installed.)                                                                                                                                            
Preparing to unpack cuda-repo-wsl-ubuntu-11-7-local_11.7.0-1_amd64.deb ...                                                                                                                                         
Unpacking cuda-repo-wsl-ubuntu-11-7-local (11.7.0-1) over (11.7.0-1) ...                                                                                                                                           
Setting up cuda-repo-wsl-ubuntu-11-7-local (11.7.0-1) ...                                                                                                                                                                                                                                                                                                                                                                             
The public CUDA GPG key does not appear to be installed.                                                                                                                                                           
To install the key, run this command:                                                                                                                                                                              
sudo cp /var/cuda-repo-wsl-ubuntu-11-7-local/cuda-B81839D3-keyring.gpg /usr/share/keyrings/                                                                                                                                                                                                                        

When I run the suggested command, nothing changes. I get the same error.

Any help is much appreciated.

3 Likes

Same here, it seems Option1(recommended) in the instruction does not work for me…
CUDA on WSL :: CUDA Toolkit Documentation (nvidia.com)

My Ubuntu is 18.04.5 LTS downloaded from Microsoft Store on WSL2 platform, Windows10 Pro(20H2), 19042.1706. Cuda driver is successfully installed on Windows.

1 Like

Hmm, we can have someone on the packaging/installer side to look at why that particular one is failing on this distribution.

In the meantime this should unblock you:
Go to our CUDA Toolkit dowload page and use the .run file: CUDA Toolkit 11.7 Update 1 Downloads | NVIDIA Developer

Thanks,

1 Like

@Javalama @rboissel

The post-installer is throwing this error because it expects the keyring to be in a different file. This should work:

# Save they key because we will swap it back after installing.
sudo mv /usr/share/keyrings/cuda-archive-keyring.gpg \
        /usr/share/keyrings/cuda-archive-keyring.gpg.bak

sudo cp /var/cuda-repo-wsl-ubuntu-11-7-local/cuda-B81839D3-keyring.gpg \
        /usr/share/keyrings/cuda-archive-keyring.gpg

sudo dpkg -i cuda-keyring_1.0-1_all.deb

sudo mv /usr/share/keyrings/cuda-archive-keyring.gpg.bak \
        /usr/share/keyrings/cuda-archive-keyring.gpg

How I went about debugging this:

  • Enable script debug messages with sudo dpkg -D2 -i cuda-repo-wsl-ubuntu-11-7-local_11.7.0-1_amd64.deb
  • Process forks to run post install script right before the error message: D000002: fork/exec /var/lib/dpkg/info/cuda-repo-wsl-ubuntu-11-7-local.postinst ( configure 11.7.0-1 )
  • Inspect the post installer script (cat /var/lib/dpkg/info/cuda-repo-wsl-ubuntu-11-7-local.postinst)
  • Post installer script thinks that the B81839D3 key should be located at /usr/share/keyrings/cuda-archive-keyring.gpg not /usr/share/keyrings/cuda-B81839D3-keyring.gpg.
12 Likes

@Javalama @rboissel

There is an issue with the post-installer – it expects the key to be in a different file. This was the workaround I did:

# Save the key because we will swap it back after installing.
sudo mv /usr/share/keyrings/cuda-archive-keyring.gpg \
        /usr/share/keyrings/cuda-archive-keyring.gpg.bak

# Move the key to the right location.
sudo cp /var/cuda-repo-wsl-ubuntu-11-7-local/cuda-B81839D3-keyring.gpg \
        /usr/share/keyrings/cuda-archive-keyring.gpg

# Install.
sudo dpkg -i cuda-repo-wsl-ubuntu-11-7-local_11.7.0-1_amd64.deb

# Swap the old key back!
sudo mv /usr/share/keyrings/cuda-archive-keyring.gpg.bak \
        /usr/share/keyrings/cuda-archive-keyring.gpg

How I went about debugging this:

  • Run dpkg with installer script debug output: sudo dpkg -D2 -i cuda-repo-wsl-ubuntu-11-7-local_11.7.0-1_amd64.deb
  • dpkg tells us that we fork to a process right before the error is thrown: D000002: fork/exec /var/lib/dpkg/info/cuda-repo-wsl-ubuntu-11-7-local.postinst ( configure 11.7.0-1 )
  • Look inside the post-install script: cat /var/lib/dpkg/info/cuda-repo-wsl-ubuntu-11-7-local.postinst
  • The post-install script expects that the B81839D3 key is in /usr/share/keyrings/cuda-archive-keyring.gpg not /usr/share/keyrings/cuda-B81839D3-keyring.gpg
5 Likes

I have the same problem and unfortunately, your method does not help me.

I also get the same error message for both suggested methods at CUDA on WSL :: CUDA Toolkit Documentation. Neither of the fixes above resolves the issue.

I also encountered this problem. Windows 10 (21H2), Uduntu 20.04, CUDA 11.7.

1 Like

Thanks. I was tried to install cuDNN to ubuntu 20.04- cuda 11.7 and got this error message
I didn’t have cuda-archive-keyring.gpg so I didn’t need the backup.
I simply perform:

sudo cp /var/cudnn-local-repo-ubuntu2004-8.4.1.50/cudnn-local-E3EC4A60-keyring.gpg /usr/share/keyrings/cuda- archive-keyring.gpg

And then dpkg worked.

15 Likes

Used your tips, it works for me.
sudo cp /var/cuda-repo-wsl-ubuntu-11-7-local/cuda-B81839D3-keyring.gpg /usr/share/keyrings/cuda-archive-keyring.gpg

17 Likes

Thanks sudo cp /var/cudnn-local-repo-ubuntu2004-8.4.1.50/cudnn-local-E3EC4A60-keyring.gpg /usr/share/keyrings/cuda-archive-keyring.gpg works

11 Likes

This one worked for me.
To check if it worked I first looked in the directories using “dir” to make sure the folder and files were matching what I had.

1 Like