Setting up Julia in WSL (Windows Subsystem for Linux)

Hi everyone!

Does anyone know of a good step-by-step tutorial explaining how to install Julia under WSL (Windows Subsystem for Linux)? Bonus points if it could also explain how to get VSCode to work with Julia, when also running VSCode from inside WSL? I had trouble finding any guide more specific than something like ‘install julia and then…’.

Installing Julia is very easy with juliaup (the recommended way). Just execute this from your WSL terminal (you get this from the official installation webpage. This will default to the windows version of the commaned but you can click on the small text beneath the command to change to unix):

curl -fsSL https://install.julialang.org | sh

I am not sure how you would connect this VSCode installed in Windows however. I think the easiest way would be to install VSCode inside WSL as well and then it “should just work”:tm:.

But why do you want to use WSL in the first place? Windows is a first class citizen for Julia and everything works just fine (except interrupting stuck threadS IIRC - but that’s a Windows incapability)

1 Like

But why do you want to use WSL in the first place?

Mainly because we already had VSCode installed under WSL from another project. Also because if we’re working on some package, and most of its other developers use Linux, there might be something that doesn’t work on Windows and it might be easier to run on Linux that spend time tracking down all the little non-portable things.

@johnomotani, I can see why you want WSL2 or git or whatever identical setup to your Linux; ideally WSL2 would support all Linux programs including Julia (since Windows/WSL2 includes a full Linux kernel). I know Julia has been changed to support WSL, so that’s not the case, the support effort should all be on Microsoft’s side…

Julia aims to be very cross-platform (even to WSL2). Stuff should generally work that way, at least non-GUI, i.e. what’s built-in. But while Linux has tier 1 support, and native Windows too, that doesn’t mean WSL (Linux in Windows) is explicitly supported in any way by Julia, with a support tier, I believe it’s best-effort support. I see it might be tier 3 support (or might only apply to the OneAPI package using WSL2).

With GUI libraries, then yes, also, and while WSL2 allows GUI (WSLg or WSL2g, whatever its called, I’m not sure it’s explicitly supported by Julia, I think it would since some WSL2 add-on?), I’m not sure you would want that.

I.e. you can add a Linux distro, like Ubuntu, to Windows, and then you would the GUI toolkits, like GTK.jl or QML.jl to target Linux, and it would appear in Windows, but you would be bypassing their capabilities to target Windows GUI directly, and not need a Linux distro installed.

Yes, but we’re scientists not professional package developers, and might do something very hacky like

git_diff = String(read(setenv(`git diff`; dir=project_dir)))

which works on Linux (assuming git is installed), but I would be surprised if it worked on Windows!

FWIW, it works for me on my on Windows w/o WSL.

2 Likes

I’m not on Windows to test that in native (or in WSL2). I assume it works in WSL2, but might it also work in native Windows?

While git diff worked for me (in shell), is installed for me in Linux (and you simply have to install it in Windows and/or use Powershell, see the link), this didn’t:

julia> git_diff = String(read(setenv(`git diff .`; dir=".")))
warning: Not a git repository. Use --no-index to compare two paths outside a working tree
usage: git diff --no-index [<options>] <path> <path>
...
ERROR: failed process: Process(setenv(`git diff .`; dir="."), ProcessExited(129)) [129]

I think not a eal error to worry about (just because showing help, i.e. it ran?), but might still be of interest for you: