Using Windows Subsystem for Linux (WSL) |
The instructions below apply only to those using Windows as their primary operating system. We recommend WSL over Cygwin or VirtualBox or dual booting Linux — unless you already know how to do that! See C++ Installation Choices for Your Operating System.
-
You'll need Windows 10, Version 1709 (2017 Fall Creators Update) or later to use WSL
You can check your version by going to Start Menu → Settings → System → About.
And under the "Windows specification" section, look for the "Version". -
Turn on "Windows Subsystem for Linux":
Start Menu → Settings → Search for "Turn Windows features on or off".
From that menu, check the box next to "Windows Subsystem for Linux"
Also, check the box next to "Virtual Machine Platform" and
check the box next to "Windows Hypervisor Platform". -
You'll need to reboot your computer now.
-
Go to the Microsoft Store, https://aka.ms/wslstore,
If you run into problems on this step, perhaps with errors about needing to update a kernel, you can try these steps manually:
Click "Open" to launch the store.
Choose the Ubuntu distribution, and press "Get" and "Install" to download.- Open an Administrator Powershell and type these commands:
wsl --shutdown wsl --set-default-version 2 wsl --update wsl --shutdown wsl --install -d Ubuntu
-
After the download is finished, press "Launch" (or "Open").
This will Open the WSL/Ubuntu terminal and Install Ubuntu on Windows.
You will be asked to choose a username & password. -
You will probably want to "Pin" Ubuntu to your Start menu.
You can do this by searching for "Ubuntu" in your start menu, and then right clicking on the icon. -
Install Ubuntu updates
Type these commands into your WSL terminal:sudo apt update sudo apt dist-upgrade
And press 'y' to continue.
During the installation process, you may be asked for permission to restart services on future upgrades without asking. It should be safe to say "yes".
-
Install the necessary packages for this course:
sudo apt install g++ clang gdb lldb zip valgrind
And press 'y' to continue.
Install Dr. Memory for WSL:
Follow these instructions...-
Install a good code editor on Windows.
If you don't already have a favorite, we recomend Sublime Text. -
Create a new directory for your work for this course on Windows.
Save the sample files to this directory.NOTE: It's easier if you avoid spaces or other non-alphanumeric characters (underscore is fine) in your file & directory names.
-
In your WSL terminal, go to your directory for the
course.
Windows paths are available in WSL from the /mnt/ mount point.
For example, if you saved the file here:
C:\Users\myusername\Documents\DataStructures\temperature.cpp
cd /mnt/c/Users/myusername/Documents/DataStructures/ ls
And you should see your file.
NOTE: If you have spaces in your directory or file names, you'll need to escape them with a backslash. E.g., Data\ Structures.
Now compile the file:
clang++ -g -o temperature.out temperature.cpp
And then run it:
./temperature.out
Or to test it through the memory debugger:
drmemory -- ./temperature.out
Or:
valgrind ./temperature.out
OPTIONAL: To disable the tab-complete bell in WSL terminal (it quickly gets annoying):
CAUTION: Some students have reported problems with specific keys on their keyboard no longer working after attempting to follow these instructions. If this happens to you, you may need to un-install and re-install WSL.
NOTE: Do not attempt to edit WSL system files from Windows. The permissions and filesystem will get messed up and you'll need to reinstall everything to recover.
From the WSL terminal (using vi to edit the file):
sudo vi /etc/inputrc
Scroll down to the line:
# set bell-style none
press 'x' twice to uncomment that line:
set bell-style none
press ':wq' and enter to save the file.
You'll need to close and restart your WSL terminal for it to take effect.
OPTIONAL: You may want to disable Ctrl Key Shortcuts (personal preference):
With an Ubuntu terminal open, left-click the Ubuntu icon in the upper left,
chose Properties, and make sure "Enable Ctrl key Shortcuts" is unchecked.
If you leave the box checked then Ctrl+D will not send EOF signals.
It's not critical for this course, but this change might be useful in a Python
command line interface (CLI). Note: the checkbox does NOT affect Ctrl+C or Ctrl+Z.OPTIONAL: Configure WSL to start in your home directory or Data Structures directory.
From your WSL terminal, type:echo 'cd /mnt/c/Users/myusername/Documents/DataStructures/' >> ~/.bashrc
Replacing /mnt/c/Users/myusername/Documents/DataStructures/ with the starting directory of your choice on your system.
NOTE: Do not attempt to edit WSL system files from Windows. The permissions and filesystem will get messed up and you'll need to reinstall everything to recover.
The next time you close and restart your WSL terminal, it will start in the directory you specified above.
-
Now, Test Your Installation.