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 (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" -
You'll need to reboot your computer now.
-
Go to the Microsoft Store, https://aka.ms/wslstore,
Choose the Ubuntu distribution, and press "Get" to download. -
After the download is finished, 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. -
Open a WSL terminal:
From the Microsoft Store, press "Launch" or choose the Ubuntu icon from your Start menu.
The first time you open the WSL terminal, it will install Ubuntu on Windows.
Then you will be asked to choose a username & password. -
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 gcc-multilib g++-multilib
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 bash 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
To disable the tab-complete bell in WSL bash 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 bash 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 bash terminal for it to take effect.
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.-
Now, Test Your Installation.