Hugo on BashOnWindows (Windows Subsystem for Linux)

Does anyone have any tips for installing and using Hugo in BashOnWindows, which is also known as Windows Subsystem for Linux (WSL)? I want to do this because then I’ll be able to have the same setup and use the same commands on my Windows and OSX machines, and when I ssh to my web-hosting provider (DreamHost). I’ll also be able to use nix symlinks on Windows :grinning:.

I’d appreciate any tips!
Thanks,
N

I’m pretty sure you would have to build it yourself – whether it will work or not depends mainly on how mature/finished the Windows subsystem is. I’ve seen some discussion over at the Go issue tracker.

But try; Hugo should in its core be pretty straight forward, but the watcher/reload part is heavy on syscalls, so that could be interesting re. bash on Windows.

I suggest you just try it and report back any issues.

I just tried it and it’s was not necessary to build it myself. I have downloaded this package: hugo_0.16_linux-64bit.tgz (https://github.com/spf13/hugo/releases/download/v0.16/hugo_0.16_linux-64bit.tgz), extracted it and executed hugo.

Site generation and server worked out-of-the-box. The automatic re-generation (-w) after changing a post does not work.

I was not able to get hugo server working out of the box, or working at all. I do not have AV installed, only Windows Defender. Running latest Windows 10 (2018/04/26).

I opened TCP/1313 in windows firewall inbound, but that did not help. netstat from CMD did not reveal 1313 port was open. Even opening one WSL window with hugo server running, I cannot curl to localhost:1313 from another WSL window.

I also tried setting --bind 0.0.0.0 but that did not change anything.

Any suggestions on getting hugo server working on windows subsystem for linux?

image

Have you tried simply installing the Ubuntu packaged version? It should be available. The default installation of WSL is Ubuntu without a GUI. You can, if you prefer, use one of the other distro versions from the store.

Hi @TotallyInformation

I have installed OpenSUSE which does not have hugo in the repository, but I don’t see how this would change anything.

The issue I am having is hugo server command not working. The rest of hugo works fine.

Thanks.

Hi, they claim this port problem is a general problem in wsl.exe.


Generally, 0.0.0.0 means “all IP addresses on this box” so, that approach might be problematic in that, it’ll try binding some IP that has that port range blocked (wild speculation), though I have not tested. I’d leave that off, because hugo server defaults to binding port 1313 to 127.0.0.1.

What hugo server command exactly are you running? Did you get any hints in the log from the --verbose switch?

Did you try netstat -an?

Did you try hitting the problem with a big hammer and just allowing all traffic to and from the wsl.exe program itself and not just the port?

1 Like

Hi there … I just went through this myself and hugo with WSL on windows is working great … super fast … plus running build scripts like gulp , npm work smoothly. I cant speak to your specific issue but you need to get WSL working first. I had some wierd issues with the windows store and had to do rebuild windows / reinstall and then select ubuntu. I just put the prebuilt binary in the path location for Hugo and it is working out of the box. maybe try ubuntu ?

one of the comments from the microsoft bug report said

Tried all your solutions but failed.
Reset windows and reinstall ubuntu from windows store saved my time.

that was my experience too

1 Like

Always best to start with the simple things first - then work through the more complex options. As others have said, best to have a simple, working WSL first.

Having recently rebuilt my PC, I’d not got round to reinstalling WSL/Ubuntu. So, now done.

  1. Install WSL from Windows Features
  2. Install Ubuntu from Windows Store
  3. Run Ubuntu, do initial config - create user
  4. sudo apt-get update && sudo apt-get upgrade
    Don’t install hugo from apt-get, it gives version 0.16
  5. wget https://github.com/gohugoio/hugo/releases/download/v0.40.1/hugo_0.40.1_Linux-64bit.deb
  6. sudo dpkg -i hugo_0.40.1_Linux-64bit.deb
  7. hugo version → 0.40.1
  8. hugo new site test1
  9. cd test1
  10. hugo server
  11. test from PC browser → get the expected blank page, no 404’s

All working. Tried on the default 1313 port and on a couple of random alternative ports.

Incidentally, I couldn’t get snap to work under WSL. But I’ve never used it before and I didn’t really try, it just didn’t work first time when I installed it so I removed it again and used the downloaded deb instead.

This is actually a case where working under Windows is actually rather easier than doing things in Linux.