1.1.8. Windows 10: Windows Subsystem for Linux (WSL)

These setup instructions are for setting up Ubuntu on Windows 10, through Windows Subsystem for Linux (WSL).

Things to note before starting

  1. Each step involves either copy+pasting a command, or clicking on a download link.

  2. Admin privileges are needed for some steps: check if you can run sudo ls, entering the correct password. If you can’t, perhaps ask an administrator to do that step, and you can do the others that don’t require it.

  3. If you run into any problems, please just ask a clear question on the AFNI Message Board.

Install Linux

  1. Click here to install WSL 1 (noooot WSL 2), and probably select “Ubuntu 20.04” as your desired flavor of Linux:
    We list the same steps below, with some (possibly helpful) additional comments.

    NB: It may not be possible to run Windows PowerShell while the OS is in “S mode”. Since the PowerShell is needed to install WSL, you might have to leave S mode to be able to have Linux on current Windows 10. It may not be possible to re-enter S mode once you leave, so please be aware of this choice.

    How to switch out of S mode if you want:

    Windows Start Menu key -> Settings (or gear icon) -> Update & Security -> Activation (in left panel) -> under “Switch to Windows 10 Home” select the “Go to the Store” link by the shopping bag -> Select the “Get” button under “Switch out of S mode”.

    Step 1: Enable the Windows Subsystem for Linux

    Open PowerShell as as administrator:
    WinKey+r -> type “powershell” -> Ctrl+Shift+Enter -> select “Yes” to make changes to your computer
    ... and the top bar of the terminal that opens should have “Administrator: Windows PowerShell”
    Copy the terminal text:
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    
    To be able to paste into the PowerShell terminal: right click on PowerShell top bar -> Properties -> under “Options” tab and “Edit Options” box, put a check next to “Use Ctrl+Shift+C/V as Copy/Paste”. After this, you can use Ctrl+Shift+c to paste the above dism.exe ... command; then hit Enter to run it.

    Restart Windows device

    (jump to) Step 6: Install your Linux distribution of choice

    Select Ubuntu 20.04 LTS.
    On next page, click “Get” button under Ubuntu 20.04 LTS.
    Click on “Install” when asked.
    Click on “Launch” when asked.
    Wait for the the installation to finish.
    Create a user account (UNIX username) and password when prompted in the terminal.

    Congratulations, Phase One of installation is complete, but there is more to go...

    Close the terminal before proceeding to the next step.

Install VcXsrv Windows X Server

  1. Click here to start automatic download:
    Click/open the downloaded vcxsrv*.exe, and allow permissions for it.
    Use default installation settings.
    When the installer finishes, you should have a new XLaunch icon on your desktop

  2. Now and forever when you want to run the WSL terminal:
    First doubleclick on the VcXsrv/XLaunch icon on your Desktop
    Select “Next” for all prompts, and then “Finish”.
    Then start Ubuntu, for example by selecting WinKey -> Ubuntu, or by searching for “Ubuntu” in the search bar. (After opening, you can rightclick on the icon that appears in the bottom panel, and select “Pin to taskbar”, to be able to select more quickly.)
    Sorry, this is not our design!

  3. To enable copy+paste ability in Ubuntu terminal, right-click on the toolbar at the top of the Ubuntu terminal, and select “Properties”; in the Options tab, make sure the box next to “QuickEdit Mode” is selected.

    You can then paste into a terminal by either right-clicking or hitting the “Enter” key. (To “copy” text that is in the terminal, just highlight it, and then you should be able to right-click to paste; to “copy” text from outside the terminal, you probably need to highlight it and hit “Ctrl+c”.)

  4. Copy+paste:

    echo "export DISPLAY=:0.0" >> ~/.bashrc
    echo "setenv DISPLAY :0.0" >> ~/.cshrc
    echo "export NO_AT_BRIDGE=1" >> ~/.bashrc
    echo "setenv NO_AT_BRIDGE 1" >> ~/.cshrc
    
    Purpose: First, set DISPLAY properly, so you can open GUIs like afni, suma, etc. Then, avoid having some very-non-necessary GTK warnings from programs.

  5. Close (exit) Ubuntu terminal, so that changes are effected the next time you open it.

More setup tips for Ubuntu+Windows

  1. The default profile “use colors from system theme” shows an all-black terminal. To adjust this to something nicer:
    Go to the terminal’s menu bar,
    Select the Edit tab, then Profile,
    Turn off “use colors …”, and just pick a scheme+palette that you like.

  2. Note:
    In gnome-terminal, things are similar to other Linux implementations. The middle button pastes whatever is highlighted in the WSL terminal or other gnome-terminal: shift-ctrl-c copies, and shift-ctrl-v also pastes.

Install prerequisite: AFNI and package dependencies

  1. Start a new Ubuntu session. To check your version, copy+paste:

    lsb_release -a
    
  2. For …

    Purpose: Complete your life’s ambition to have working AFNI on your Windows computer (though, realize it is Linux that makes this happen!).

A note on transferring data between Ubuntu and Windows

  1. You can “see” your Windows file system from the Ubuntu side, where it appears as /mnt/c/. For example, if your Windows username is USERNAME, then the following would copy a file called FILE.pdf on your Windows Desktop to your current Ubuntu terminal location:

    cp /mnt/c/Users/USERNAME/Desktop/FILE.pdf .
    
  2. To mount external devices (e.g., a USB) from the Ubuntu side. Let’s say your external device appears as the “G:” drive on Windows when you plug it into a USB port. You could mount that drive from Ubuntu as follows, where—
    the first command makes a mount point location (‘g’ is a convenient label here), and
    the second mounts the external drive to it::

    sudo mkdir /mnt/g sudo mount -t drvfs G: /mnt/g

    If you had a file FILE.nii on the “G:” drive USB, you could now copy it to your present location with:

    cp /mnt/g/FILE.nii .
    

    To safely unmount the USB before unplugging it, type:

    sudo umount /mnt/g
    

    Bonus note: you can mount/unmount network shares in a similar way:

    sudo mkdir /mnt/share
    sudo mount -t drvfs '\\server\share' /mnt/share
    
    ...
    
    sudo umount /mnt/share