Setting Up a Programming Environment via Windows 10 Bash
Steven J. Zeil
In 2016, Microsoft added to Windows 10 (64 bit) the ability to run Ubuntu Linux in parallel with Windows. Variously referred to as “Bash on Windows”, or “Ubuntu on Windows”, and more officially as the “Windows Subsystem for Linux” (WSL), this is a very useful way to work with Linux-based software development tools from a Windows 10 machine.
- What it is
- This provides a Linux OS running alongside Windows. Both share the same hard drive (and can access each other’s files), and the clipboard supports copy-and-paste between the two quite naturally. (A small thing, perhaps, but one that I find quite important in practice.)
- What it is not
- This provides a “server”-style installation of Linux. There is no full Linux desktop. The main entry point to Linux is a text-only
bash
shell for entering Linux commands. The ability to inter-script (i.e., to launch Windows programs from Linux or vice versa) seems quite limited. - What it can be
- With VSCode running natively in Windows, you get a very natural way to run Linux compilers and other development tools.
Combined with an X server running under Windows, you can launch and run GUI programs from Linux.
In this document, I’ll walk you through the process of setting up a programming environment consisting of:
- The basic Linux on Windows system.
- An X server (optional: to display Linux-based GUI programs on the Windows-managed display screen).
- Java and C++ compilers
- The
git
version control program. - The VSCode IDE
Personally, I favor this approach for C++ development, but will usually do Java development natively in Windows, using VSCode as my IDE in both cases.
1 Get the Windows 10 Subsystem for Linux
You’ll find the instructions here.
After installing and restarting your machine, use the taskbar to search for “ubuntu”. You should see that “Ubuntu for Windows” app has been installed. Select it to run bash
.
Try some simple Linux commands such as `ls`, `cd`,
and `pwd`. You'll find that your Windows lettered
disc drives are available under '/mnt'. For example,
your `C:` drive is `/mnt/c`.
1.1 sudo apt-get
Before we continue on, let’s introduce a couple of the programs that you will be using through the rest of this process.
-
apt-get
is the program you use to update your Linux software and to install or uninstall software packages.apt-get
, however, can only be run by a Linux administrator. Now, you are the administrator for the Linux OS you have just installed, but for safety’s sake you run most programs as an ordinary, non-administrator user. -
sudo
is a command that says “run the following as the administrator”.
For example, the following sequence is how you update your Linux software:
sudo apt-get update
sudo apt-get upgrade
The first command actually fetches the latest information about what updates are available. The second installs the updates. The “sudo” in front causes them to be run as the administrator. When you give the first “sudo” command, you will be prompted for your password to prove that you really are the account owner. After that, sudo
remembers your identity for a short period of time, so you can give multiple sudo
commands in a row, only asked for your password once, as long as you don’t take too much time in between.
Go ahead and give those two commands now.
Try to give those two commands on a fairly regular basis so your Linux OS stays up to date. You’ll actually be notified when you start a new
bash
session if there are updates awaiting.
Close your bash
session for now by giving the command
exit
2 Installing the Compilers & Tools
Now we’re ready to start installing some real software. You will need
- The Java compiler and run-time system.
- The
g++
compiler for C++. - The
gdb
debugger. - The
make
project build system. - The
git
version control command.
If you are only interested in C++ or only interested in Java, you can skip over the steps for the other language.
We’ll install all of these with the following apt-get
commands:
sudo apt-get install default-jdk
sudo apt-get install g++
sudo apt-get install gdb
sudo apt-get install make
sudo apt-get install git
Once those are done, verify your installation by typing the following in bash
:
java -version
g++ --version
gdb --version
make --version
Each should respond with an identifying message making clear that the software is installed and running.
3 Installing VSCode
Although VSCode can be installed in Linux, I recommend installing it as a Windows application and using its remote development features to connect to your WSL Linux.
-
Get VSCode here and install it in Windows.
-
Run VSCode. In a freshly installed state, it does not know how to work with C++ or Java, and it does not know how to do remote development. We’ll fix these limitations by immediately installing some extensions.
Click on the button to enter the list of extensions.
-
Use the text box at the top of the left column to search for “C++”. Locate and install the following extensions:
- Remote - WSL
- C/C++
- Better C/C++ Syntax
- Java Extension Pack
(If you already had VSCode on your Windows PC, you may have already installed some of these extensions. However, after adding the
Remote - WSL
extension, you will want to check that each of the other extensions says that it is “installed globally” or “installed in WSL”. If not, reinstall it.)
4 Try it Out
- In a WSL bash window, create a convenient directory and
cd
into it. - Download a simple C++ project:
wget https://www.cs.odu.edu/~zeil/cs252/sum21/Public/make/makeTry.zip unzip makeTry.zip ls
-
You should have a new
makeTry
directory containing a simple project. -
Launch vsCode from that directory:
cd makeTry code .
The code command signals Windows to open an instance of VSCode looking at the current directory (
.
).Try looking at the directory from within VSCode. Click on some of the files to load them into the editor.
-
Follow these instructions to tell VSCode to use “
make
” to compile this project.Try building and running the project.
-
Follow these instructions to configure the debugger to run one of the executables for this project.