Ubuntu – Reduce size of a WSL installation (Ubuntu 18 on Windows 10)

18.04windowwindows-subsystem-for-linux

I need a few basic bash commands, so I have WSL installed (Ubuntu 18.04).

With cygwin everything I need takes about 150MB. But WSL takes over 1GB !! Not good for my small SSD.

I'm sure there's loads of stuff/junk in there that isn't necessary (or even possible to use). Has anyone managed to reduce the size?

I did sudo apt autoremove but that doesn't help at all (obviously).

UPDATE
The answers below are super, but the above question remains unanswered. Suppose that WSL is being used (for various bash commands) – that is the premise, not wine/cygwin/vm/dualboot/docker/etc.
How would you strip it of stuff that can't be used within Windows anyway? I've read that there is all sorts of dead weight in there that can't be used. For example, if all you need is a collection of bash commands, how do you remove all the GUI and X stuff. Just as an example.

UPDATE2
I accepted one of the good answers below, but it doesn't fully answer the question. I hope in time someone will add to this discussion. I was hoping someone had a list of stuff that can be removed. I know how to remove stuff, what I don't know is what to remove.

Best Answer

  • WSL is a full OS, so it takes up more CPU/MEM/DSK than CygWin but less than a VM

    So it depends on your use case:

    • if all you need is tail on Windows, you just install the GNU Utilities for Windows.
    • If you need something more advanced, you install CygWin,
    • If you want to have snaps, containers, ... you install WSL
    • if you need all the whistles and bells of both Windows and Ubuntu you go:

      • dual-boot if you have <16G of RAM
        or
      • Virtual Machine with Ubuntu as a host and Windows in a VM if you have lots of RAM (24G or more)
    • if you need only one or a few Windows utilities┬╣, you install Ubuntu without Windows but with wine
    • If you need Ubuntu, just wipe Windows because Windows takes up much more space on your hard drive than Ubuntu! >:-)

    Having said all that, you can always do the following to strip WSL of stuff that you don't need:

    apt list --installed
    apt purge WhateverYouDontNeed
    sudo apt autoremove
    sudo apt autoclean
    

    ;-)

    ┬╣ Definition of "utility": a small application that does not exist under Ubuntu E.g. Notepad++, DNSBench, ... Office is not a utility: it's a hog: go dual-boot ;-)

  • Related Question