DEV Community

Cover image for Ongoing notes on things I did to get WSL2 to work
MeStrak
MeStrak

Posted on • Updated on • Originally published at mestrak.com

Ongoing notes on things I did to get WSL2 to work

In the interests of productivity, and many issues trying to get dev stuff to work on my Windows workstation I started to use WSL 2 (I skipped WSL 1).

This post will be used for ongoing notes of things that I had to fix during the setup. It might not be complete as I'm starting my notes after the fact but I'll do my best to remember everything.

All the fixes are actually simple, but hopefully it will still be useful to save some time for people facing the same issues.


NPM/Yarn install not working

Unfortunately I don't have a log of the exact error messages from this time, but when trying to install these package managers I got an error message (something related to not being able to connect - I couldn't even ping anything external).

The fix 🚀

DNS settings had not been configured, even pinging external sites didn't work.

  1. Create a file: /etc/wsl.conf.
  2. Put the following lines in the file in order to ensure the your DNS changes do not get blown away
    [network]
    generateResolvConf = false

  3. In a cmd window, run wsl --shutdown

  4. Restart WSL2

  5. Create a file: /etc/resolv.conf. If it exists, delete and replace existing one with this new file (sudo rm /etc/resolv.conf to delete, and if you get a warning about an existing swap file then D to delete it).

  6. Put the following line in the file
    nameserver 8.8.8.8 (or use your DNS server instead of 8.8.8.8 which is a Google DNS server)

  7. In a cmd window, run wsl --shutdown

  8. Restart WSL2

Credit: this fix is copied directly from this gist by @coltenkrauter


error: linker cc not found when compiling rust code

When running rustc I came across the following error, basically because gcc wasn't installed.

$ rustc fart.rs
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error
Enter fullscreen mode Exit fullscreen mode

The fix 🚀

$ sudo apt update
$ sudo apt install build-essential
Enter fullscreen mode Exit fullscreen mode

I did actually have more errors than this which I've written up separately, see the 404 not found error below


Package installation fails with 404 errors

Annoying errors like the one below to show when I was installing some new packages (actually after trying to install build-essential).

$ sudo apt install build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl
  libalgorithm-merge-perl libasan5 libatomic1 libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libdpkg-perl libfakeroot
  libfile-fcntllock-perl libgcc-9-dev libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0
  libubsan1 linux-libc-dev make
Suggested packages:
  cpp-doc gcc-9-locales debian-keyring g++-multilib g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool
  flex bison gdb gcc-doc gcc-9-multilib glibc-doc bzr libstdc++-9-doc make-doc
The following NEW packages will be installed:
  build-essential cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libc-dev-bin libc6-dev libcc1-0 libcrypt-dev
  libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev libisl22 libitm1 liblsan0 libmpc3 libquadmath0
  libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make
0 upgraded, 33 newly installed, 0 to remove and 33 not upgraded.
Need to get 1096 kB/35.2 MB of archives.
After this operation, 157 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Ign:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-libc-dev amd64 5.4.0-31.35
Err:1 http://security.ubuntu.com/ubuntu focal-updates/main amd64 linux-libc-dev amd64 5.4.0-31.35
  404  Not Found [IP: 91.189.88.142 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_5.4.0-31.35_amd64.deb  404  Not Found [IP: 91.189.88.142 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
Enter fullscreen mode Exit fullscreen mode

The important bit:

Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_5.4.0-31.35_amd64.deb  404  Not Found [IP: 91.189.88.142 80]
Enter fullscreen mode Exit fullscreen mode

Running with --fix-missing as suggested in the error message and a few blog posts gave the same error.

sudo apt-get update didn't work either:

$ sudo apt-get update --fix-missing && apt-get install gcc
Hit:1 https://dl.yarnpkg.com/debian stable InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:3 https://deb.nodesource.com/node_12.x focal InRelease
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-updates InRelease [111 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease [98.3 kB]
Reading package lists... Done
E: Release file for http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease is not valid yet (invalid for another 10d 6h 3min 42s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease is not valid yet (invalid for another 10d 6h 3min 50s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease is not valid yet (invalid for another 10d 6h 4min 14s). Updates for this repository will not be applied.
Enter fullscreen mode Exit fullscreen mode

The fix 🚀

The issue was that my clock was out of sync with the Windows host (I don't know why).

$ sudo hwclock --hctosys
Enter fullscreen mode Exit fullscreen mode

After this $ sudo apt update ran happily, as did $ sudo apt install build-essential.

Credit: I found this solution here

Can't add python poetry auto completions for bash

Got the error bash: /etc/bash_completion.d/poetry.bash-completion: Permission denied when running the following command:

$ poetry completions bash > /etc/bash_completion.d/poetry.bash-completion
Enter fullscreen mode Exit fullscreen mode

At the time of writing (10 Aug 2020), according to the output of $ poetry help completions this should be the command to install bash completions for poetry.

The fix 🚀

Run this command instead!

$ poetry completions bash | sudo tee /etc/bash_completion.d/poetry.bash-completion
Enter fullscreen mode Exit fullscreen mode

Credit: I found this solution here

Top comments (0)