Lando on WSL2

I think Lando is amazing. A big thank you to all those involved in creating it and thereby making container based development significantly easier. It's amazing how much of a change it makes compared to using Docker on it's own, especially if you want to do things like have a local SSL (so you can have an HTTPS permalink). If you've previously visited this tutorial, much has changed recently (in early 2024) with Lando v3.21 now being available. It makes installation a breeze. In fact this tutorial is now going to be very short and simple and probably in much less demand.

There is sometimes confusion when using Lando on a Windows machine. While it is possible to install Lando on your Windows file system, unless you are developing Windows software, then it is STRONGLY RECOMMENDED to install Lando directly in your WSL2 instance. In other words, from here on out you should be ignoring Windows documentation for Lando and looking at Linux installation docs. Remember, we are installing this in your WSL2 instance. In other words, we are installing it in Linux, which is actually very cool and very useful.

So, with the above note in mind this are now very straight forward because of the big changes in Lando v3.21. All you need to do now is just follow the Linux installation instructions found in the Lando docs. But, I'll detail what you need to do in case you want to read that here, and I have a few tips and notes from experience...

Pre-Installation Tasks

  • If you have never installed WSL2 before on your system, then simply run this command
    wsl --install from your Windows command line (running as an administrator).
  • The above command will magically setup and install everything for you -- it installs WSL2 and Ubuntu from the Microsoft Store.
  • NOTE -- if you previously setup WSL2 on your system, you should uninstall / remove whatever instance of Linux you added to it. You can usually do that just from "Add / Remove Programs" in your Control Panel. Double check that it's gone by running wsl --list in your Windows command line tool of choice. Once you've confirmed your old Linux instance is gone, then you can reinstall the Ubuntu app, or whatever flavour of Linux you installed previously.
  • You should now probably reboot your system. Why? It's not required I guess, but it never hurts and seems to clear up any little things lingering around.
  • Lastly, and optionally, you can install NodeJS via nvm as per Microsoft's recommendations.
  • Now if you load Windows Terminal you should see the Linux instance you installed (Ubuntu if you followed the above tips)

Ready for Lando Installation

  • The hard work is done. This is indeed now very easy. But wait, as is usually a good habit before adding stuff to your Linux instance, you should run:
    sudo apt update && sudo apt upgrade
  • Okay, with everything up to date you now simply run the Lando install command for Linux as found in the Lando docs.
  • As of this writing, v3.21 is still in beta, so the install script output did do a few very minor funky things. I just stayed with it, entered my admin password when required, and it all worked out nicely in the end.
  • All that is left to do now is to restart your WSL environment. That is easily done by just now popping back into a Windows Terminal and executing: wsl --shutdown and waiting maybe 10-15 seconds. Again here I also like to reboot my machine, but it's really not necessary.

Fire up Lando (aka, your first container)

We're already almost there and ready to go. We just need to do a few more things…

  • Run the lando init command in a project folder somewhere in your WSL2 user profile to get things going (including starting Docker).
  • Tweak the generated .lando.yml file if need be for your project (see Lando Docs to learn all about that if you haven't done that already).
  • Then run lando start to fire up your contains and such. This will also generate the main Lando SSL cert, as well as an SSL cert for this project.
  • Add the Lando CA to your Windows certificate store, as per the Lando security docs.
    • NOTE! The path will be to your cert in your WSL2 instance, not a Windows path like it shows in the docs linked above.
    • So, using your Windows CLI you'll need to run the command suggested in the docs, but with the path updated to your WSL instance. It will be something like this:
    • certutil -addstore -f "ROOT" \\wsl.localhost\Ubuntu\home\WSL-USER-NAME\.lando\certs\
  • If you are a Firefox user (like I am), then it used to be extra work. But starting with Firefox 120, it should now also used your Windows certificate store and #justWork.

All done! Now sit back and enjoy the latest Lando and Docker all within your WSL2. Hooray!

Photo by Casey Horner on Unsplash

© 2024 Creative Logic Tech Solutions.