The error occurs because the NVIDIA WSL driver files in /usr/lib/wsl/lib/ are corrupted, missing, or have conflicting symlinks that prevent ldconfig from updating the dynamic linker cache. You can resolve this by temporarily moving the problematic library files out of the way, running sudo apt update to complete the package upgrade, and then restoring the libraries if you require GPU acceleration.
Understanding the ldconfig Error
When you runsudo apt update or install packages on Ubuntu within Windows Subsystem for Linux (WSL), the system often triggers post-installation scripts. These scripts may call /sbin/ldconfig.real to rebuild the shared library cache. This process scans directories like /lib, /usr/lib, and specifically /usr/lib/wsl/lib for NVIDIA-specific drivers.
The specific error message indicates that ldconfig cannot create a symbolic link for libnvoptix.so.1 pointing to libnvoptix_loader.so.1. This usually happens when:
- The target file
libnvoptix_loader.so.1is missing or unreadable. - A stale or broken symlink already exists with immutable permissions.
- There is a permission mismatch between the existing files and the new installation attempt.
Step-by-Step Fix
The most reliable solution is to isolate the problematic NVIDIA libraries, allow the system update to proceed without them, and then restore them. Do not delete these files permanently unless you are certain you do not need GPU support in WSL.1. Move the Problematic Libraries
First, open your WSL terminal. Navigate to the directory where the error is occurring. You need to move the files preventing the link creation. Run the following commands to rename the directory temporarily. This preventsldconfig from scanning it during the current update cycle.
cd /usr/lib/wsl/lib
sudo mv libnvoptix_loader.so.1 libnvoptix_loader.so.1.bak
sudo mv libnvoptix.so.1 libnvoptix.so.1.bak
If you encounter "Permission denied" errors here, ensure you are using sudo as shown above. In some cases, the entire wsl directory structure might have unusual permissions inherited from the Windows host, but typically standard sudo privileges suffice for these specific library files.
2. Update and Upgrade Packages
With the problematic libraries moved, you can now run the standard APT commands without triggering the failed link step.sudo apt update
sudo apt upgrade -y
This process should complete successfully. The system will no longer attempt to link the NVIDIA OptiX libraries because they are currently hidden behind the .bak extension. If you face issues with repository keys or certificates during this phase, check our article on Resolving Certificate Verification Failure in WSL Ubuntu for add-apt-repository.
3. Restore the Libraries
Once the update and upgrade processes finish without errors, you can restore the NVIDIA libraries. This ensures that any applications requiring GPU acceleration continue to function correctly after the system update.cd /usr/lib/wsl/lib
sudo mv libnvoptix_loader.so.1.bak libnvoptix_loader.so.1
sudo mv libnvoptix.so.1.bak libnvoptix.so.1
After restoring, it is good practice to manually trigger the linker configuration to ensure the symlinks are correct in their restored state.
sudo ldconfig
If this command returns no output, it succeeded. If it throws an error again, verify that the files are not read-only and that the original names are exactly as expected.
Alternative Approach: Clean Reinstall of NVIDIA Drivers
If the manual renaming approach fails repeatedly, the NVIDIA WSL driver installation itself may be corrupted at a deeper level. In this scenario, you might need to reinstall the driver from the Windows side, as WSL relies on the host's NVIDIA driver stack. Ensure your Windows NVIDIA drivers are up to date via GeForce Experience or the NVIDIA website. Then, inside WSL, you can remove the existing WSL-specific packages if they exist separately from the main driver. However, note that in modern WSL versions, these libraries are managed automatically by the Windows driver installer. Manual manipulation of/usr/lib/wsl/lib is generally only necessary when the automatic synchronization fails or leaves orphaned files.
For users who recently migrated their environment, such as importing a distro from another machine, ensuring the file system integrity is crucial. If you recently imported a distro and are seeing unexpected permission errors, review our tips on Importing Previously Exported WSL Distro to ensure your virtual disk was mounted correctly.
Verifying the Fix
To confirm the issue is resolved, try installing a package that requires recompilation or updates linked libraries. For example:sudo apt install --reinstall libc6
Watch the output for any references to ldconfig. If the installation completes without the "Can't link" error, the problem is solved. You can also verify the status of the NVIDIA libraries by listing them:
ls -l /usr/lib/wsl/lib/libnvoptix*
You should see valid symlinks pointing to the loader version. If they appear broken, repeat the restoration steps and ensure no other processes are locking these files.
Frequently Asked Questions
Why does this error happen only during updates?
The error occurs because ldconfig runs as a post-install hook for many packages. When the package manager attempts to update the system, it triggers this hook, which scans all library directories. If the NVIDIA files are in an inconsistent state, the hook fails, halting the entire update process until the conflict is resolved.
Can I just delete the NVIDIA library files?
You can delete them, but this will disable GPU acceleration in WSL. Applications that rely on CUDA or OptiX will fail to start. It is safer to rename them temporarily, as demonstrated in the fix, so you can restore functionality once the system packages are updated.
What if I get a permission denied error when moving the files?
This suggests the files might be owned by root or have restricted attributes. Ensure you are prefixing your commands with sudo. If that fails, check if the files are marked as immutable using lsattr. You may need to use chattr -i to remove the immutable flag before moving them.
Does this affect my Windows installation?
No, this is isolated to the WSL filesystem. The files in /usr/lib/wsl/lib are essentially a mirror or interface to the Windows-side NVIDIA drivers. Modifying them in WSL does not impact your primary Windows OS stability or performance.
How do I know if my NVIDIA drivers are up to date?
Check the version number in Device Manager under Display Adapters on Windows. Compare this with the latest driver version on the NVIDIA website. WSL requires relatively recent drivers (usually within the last few months) to maintain compatibility with the Linux-side library wrappers.