Can I upgrade my existing Ubuntu installation in WSL from 16.04 to 18.04?

33,364

Solution 1

I just forced an upgrade from 16.04 and it was successful, though the process was not all well.

sudo do-release-upgrade -d

First do the upgrade. As people have reported in comments, it's likely all that you need to do before 18.04 is all set up. In a few cases like mine, it will do most of the things while showing as "failed".

In case it shows as "failed", open /etc/apt/sources.list and replace all "xenial" with "bionic", and sudo apt update && sudo apt -y upgrade. Most people should have everything done at this point.

In some cases (but not all), APT and Debian Packager may fail during the process. According to this GitHub thread, you need to remove grub and kernels, if present:

sudo apt -f purge grub-pc
sudo apt -f purge linux-image*

Repeat the last command several times as dpkg will fail after removing every package. After all those Linux images are removed, you get a fully working Bionic Beaver in your WSL.

Read more: A Guide to Upgrading your Ubuntu App’s Release – Windows Command Line Tools For Developers

Solution 2

Yes, you can!

There are now a few choices for Ubuntu in the Window Store.

Screenshot from Windows Store showing the varieties of Ubuntu available.

  • Just "Ubuntu": This will always be the latest stable, LTS version.
  • Ubuntu 22.04 LTS: For developers who want version 22.04 specifically.
  • Ubuntu 20.04.4 LTS: For developers who want version 20.04 specifically.
  • Ubuntu 18.04.5 LTS: For developers who want version 18.04 specifically.

If you installed the plain "Ubuntu" app (with no version number) before 20.04 or 22.04 was made available on the Windows Store, you may upgrade it with the following set of commands:

sudo apt update -y         # makes apt system itself up-to-date 
sudo apt dist-upgrade -y   # updates current Ubuntu packages to latest

sudo do-release-upgrade    # perform an upgrade to Ubuntu 22.04

Follow all prompts and heed all warnings. They are usually due to customization and third-party libraries or repositories you added yourself.

Official source: https://devblogs.microsoft.com/commandline/upgrading-ubuntu/

Solution 3

There is official Ubuntu18.04 in the windows store now, as well as Ubuntu16.04.

Though I haven't found any official information what is the difference between these two and the Ubuntu.

Yes, there are three different Ubuntu in windows store at the moment.

Solution 4

Disclaimer: This following procedure requires a pre-installed GNU/Linux Distributions in WSL (like OP has Ubuntu 16.04 already installed). The provided links may not work in future. You may comment below if any. It requires little knowledge of GNU/Linux command line tools e.g. tar, UnsquashFS etc. Install these tools before following this procedure.

  • Installer Executable: You need an executable importing WslRegisterDistribution function which installs the distribution. There are two ways. You can compile your own installer from source code (link1) or extract the installer from Microsoft provided Appx package(link2).

  • Get Ubuntu 18.04: Download the Ubuntu 18.04 SquashFS file. Now run old Ubuntu with WSL in that download folder and login as root user. Run the following commands below (only with root user):

cp ./ubuntu-18.04-server-cloudimg-amd64.squashfs ~ 
cd ~ 
unsquashfs -d temp ubuntu-18.04-server-cloudimg-amd64.squashfs 
cd temp 
tar -czf ../Ubuntu.tar.gz --hard-dereference * 
cd .. 
mv Ubuntu.tar.gz /mnt/c 

The cp command copies the SquashFS file in home directory (required). UnsquashFS extracts files in temp folder and tar compresses all the files in a .tar.gz format. Then mv command move that file in previous download folder. You may delete the temp folder with rm -rf ~/temp command.

  • Install: Place both the executable and tar.gz file in same folder where you want to install. You've to run a command (link1) or double click on the executable (link2) to install. It requires 15-30 seconds to install depending on you machine.
Share:
33,364

Related videos on Youtube

iBug
Author by

iBug

Updated on September 18, 2022

Comments

  • iBug
    iBug over 1 year

    I'm currently running Ubuntu 16.04 in WSL (Windows 10 v1709 or later), installed using lxrun.

    Can I upgrade it to 18.04?

    If so, how? If not, when?

    • Rajib Garai
      Rajib Garai about 6 years
      Here one can read "We will be looking at 18.04 support but do not have an official timeline yet."
    • iBug
      iBug about 6 years
      @Biswapriyo Not sure if I did it appropriately, but sudo do-release-upgrade -d then force an apt upgrade with force changed sources (xenial→bionic) worked well for me. Just make sure to remove things like linux-image and grub from WSL.
    • Biswapriyo
      Biswapriyo about 6 years
      Ubuntu 18.04 available in store: microsoft.com/en-us/store/p/ubuntu-1804/9n9tngvndl3q
  • phk
    phk about 6 years
    There also seem to be tools like github.com/Biswa96/WSLInstall and github.com/DDoSolitary/LxRunOffline which looks like could be used for the install part (haven't tested it myself though).
  • phk
    phk about 6 years
    Ahaha, the first github link from me like actually points to your repository, so nevermind. Cheers!
  • Paul
    Paul about 6 years
    FWIW, perhaps the issues you encountered were fixed in the Windows 10 April 2018 update, but I did sudo do-release-upgrade -d and it upgraded to 18.04 with no errors, it correctly set my sources.list, and no grub-pc or linux-image* packages were installed. It worked perfectly fine!
  • iBug
    iBug about 6 years
    @Paul They were installed previously and were updated together.
  • Ben
    Ben about 6 years
    Can confirm that just sudo do-release-upgrade -d works nicely now.
  • DaveTheMinion
    DaveTheMinion almost 6 years
    The two installations that have a version number on the end are intended for people that want to use a specific version and stick with it. The version that is just labeled "Ubuntu" is for those who want to always run the latest release.
  • X.Arthur
    X.Arthur almost 6 years
    Yes, later found out on some blog.
  • DaveTheMinion
    DaveTheMinion almost 6 years
    I was under the impression that if you were using the "Ubuntu" one, it would update to the latest version via the app store, but that is apparently not the case.
  • X.Arthur
    X.Arthur almost 6 years
    @DavidB It should be updated when MS has tested its stability. It seems the current 18.04 has changed a lot of things, and some need new implementation on WSL. Hopefully, the next windows release will include this.
  • DaveTheMinion
    DaveTheMinion almost 6 years
    Are you sure about this? I upgraded and everything seems to be working smoothly.
  • X.Arthur
    X.Arthur almost 6 years
    @DavidB github.com/Microsoft/WSL/issues/2960 see discussion here and here github.com/Microsoft/WSL/issues/2874. I also upgraded and nothing seems wrong. But I'm sure I saw one of the MS guys mentioned something that WSL cannot handle for 18.04. Maybe not too much related to daily personal use.
  • DaveTheMinion
    DaveTheMinion almost 6 years
    I think I saw it too, but I believe the post was an older one and is now out of date.
  • Chris Browet
    Chris Browet over 5 years
    Should be sudo apt dist-upgrade, really, or held upgrades will prevent the release upgrade
  • AlphaF20
    AlphaF20 over 2 years
    I tried sudo do-release-upgrade -d, got [sudo] password for cwang: Traceback (most recent call last): File "/usr/bin/do-release-upgrade", line 11, in <module> from UpdateManager.Core.MetaRelease import MetaReleaseCore File "/usr/lib/python3/dist-packages/UpdateManager/Core/MetaRelea‌​se.py", line 25, in <module> import apt File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module> import apt_pkg ImportError: /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0: symbol _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compa‌​reERKS4...
  • AlphaF20
    AlphaF20 over 2 years
    sudo apt -f purge grub-pc got apt: relocation error: /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0: symbol _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compa‌​reERKS4_, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference