Setting Up Your Work Environment¶
Linux Subsystem Installation¶
Unless you already have Linux installed on your machine, we recommend you install Windows Subsystem for Linux (WSL). This will allow you to run a Linux-based operating system natively within Windows, and to use Linux tools and utilities directly on your Windows machine, without needing to set up a virtual machine or dual boot the two operating systems.
To install WSL on Windows 11 follow the steps below:
1. Right-click on the Start button in the lower-left corner of your screen, and from the menu that appears, select either PowerShell (Admin), Terminal (Admin), or Command Prompt (Admin) to open the respective program with administrator privileges.
2. In case you want to avoid modifying your Windows settings and enabling Virtual Machine Systems, you may opt for installing WSL1 instead of WSL2. To do so, type the following command:
wsl --set-default-version 1
3. Now you can start installing WSL by typing:
wsl --install
4. Restart the computer.
5. Find the newly installed Ubuntu in the Windows menu by clicking on the Start button in the lower-left corner of your screen, and scrolling through the list of installed applications. Once you locate it, click on it to launch the Ubuntu terminal and start using the Linux environment on your Windows machine.
5. Find the newly installed Ubuntu in the Windows menu by clicking on the Start button in the lower-left corner of your screen, and scrolling through the list of installed applications. Once you locate it, click on it to launch the Ubuntu terminal and start using the Linux environment on your Windows machine.
6. Follow the prompts to install Ubuntu.
7. Select your username and password.
7. Select your username and password.
C++ Tools¶
You're almost ready to start using the Linux Subsystem. The only thing left is to set up C++:
sudo apt update sudo apt install build-essential
This will update your system's package list and install the necessary tools for C++ compilation and execution.
Using WLS¶
If you have experience working with Linux environments, you may skip the following instructions. However, if you are new to Linux, the following guidelines will be helpful in getting you started.
To open the Windows Explorer of your Linux Subsystem home directory, enter the following command in the terminal:
explorer.exe .
This will launch a window displaying the contents of your
home/username
directory, which you can use to create directories and files for your assignments.Linux Command Line¶
Using WSL Ubuntu command line is essentially the same as native Ubuntu. However, running GUI programs require some extra work.
Instead, WSL has the advantage that you can use Windows programs for your files freely, such as text and image editors.
For compiling and running the programs for this course, the command line is ideal.
Instead, WSL has the advantage that you can use Windows programs for your files freely, such as text and image editors.
For compiling and running the programs for this course, the command line is ideal.
Useful Linux commands:
pwd # Print Working Directory - shows the folder you are currently in ls # List - lists the files in your current folder cd FOLDER # Change Directory to FOLDER - opens FOLDER cd .. # - opens the parent folder of your current location cd # - opens your home folder vim FILE # Opens (or creates) FILE in vim, a simple command line text editor rm FILE # Remove - deletes FILE rm -r FOLDER # - deletes a folder and its contents mv FILE1 FILE2 # Move - moves/renames FILE1 to FILE2 cp FILE1 FILE2 # Copy - copies FILE1 to FILE2 make PROGRAM # Compiles PROGRAM using the rules in the Makefile file in current directory clear # Clear the terminal screen (Ctrl-l also works) reset # Reset and clear the terminal
Keyboard shortcuts for Bash:
Ctrl + a : Navigates to the beginning of the line Ctrl + e : Navigates to the end of the line Alt + b : Back (left) one word Alt + f : Forward (right) one word Ctrl + u : Clears the line from the cursor to the beginning Ctrl + c : Kills the current command being executed (useful if run into an infinite loop) tab : Attempts to autocomplete your command
Text Editor¶
We do not require you to use any specific text editor. It can be a text editor within WSL Ubuntu or a text editor in Windows or whatever you like.
Some examples:
- Vim (Linux, installed by default, but most people would find it difficult to use)
- Notepad++ (Windows, much better for writing code than default Notepad, easy to use)
- Visual Studio Code (Windows, popular code editor, may be slightly excessive)
- gedit/Emacs (Linux, both are general GUI text editors with features that make coding more convenient).
- Note: For Emacs or other GUI text editor to work with graphical capabilities, you may need to install an X server. You can do this by running the command
sudo apt install xserver-xorg
. After installing the X server, it's recommended to reboot for the changes to take effect.
It is not recommended to set up a fully fledged IDE as that can result in getting different kinds of warnings and suggestions that are not in line with the course material, and you may miss out on learning important aspects of C++ development or even arrive at incorrect solutions if you follow the guidance of the IDE more closely than the course material.
If you are using WSL and you are unsure which text editor to pick, the easiest way to get started is likely Notepad++.
Common problems¶
1. If you download files on Windows and move them to WSL directory, in some cases you don't have appropriate permissions for those files in WSL. In that case, use the chmod command:
sudo chmod 777 -R [FILE/FOLDER]
This command will ensure you have all the permissions for that file or all the files under a folder.
2. If you extract or otherwise add files to a WSL directory and you have the directory open in Windows explorer, you probably won't see the new files immediately, but rather you have to refresh the folder by pressing F5 or perhaps just re-opening the folder.
Give feedback on this content
Comments about this material