Installing Windows Subsystem for Linux
Install the Windows Subsystem for Linux
The Windows Subsystem for Linux provides a mechanism to use Linux on a Windows machine.
Run the Command Prompt App as an Administrator
- In the search bubble at the bottom of the screen, type com and hit enter.
- In the window that pops up, find the App "Command Prompt"
- If the "Command Prompt" App is on the right side of the window, click on the "run as administrator" line. (If the "Command Prompt" App is on the left side of the window, click on the corresponding arrow to get it to appear on the right side.)
- You should be asked to give permission to the App and the "Command Prompt" window should have "Administrator" as part of the title for the window. If it doesn’t, close the window and repeat from step 1. (If you just click on the App icon, the App will not open with administrator permission.)
Install correct version of Ubuntu
- Type wsl --install on the prompt line. wsl stands for Windows Subsystem for Linux. The computer will print many lines of text in the window . Be patient.
- When the text prompts you to reboot the system, reboot your laptop.
- When your laptop is back online, it should open the "Command Prompt" automatically. There may be an error message. Close the window.
- Reopen the "Command Prompt" window. (Use the instructions given above.)
- Type wsl -l this command will prompt the computer to tell us which version of Ubuntu is installed. Most likely it will be the basic version. We want to use Ubuntu 24.04
- Type wsl --install -d Ubuntu-24.04 This tells the computer to install the desired version of Ubuntu. Check the text the computer displays to verify that this is the case.
- When prompted, enter a username. This does not need to be your MSOE username.
- When prompted, enter a password. The cursor will not move as you type. Be sure to record this password as we will need it later and there is no way to recover it. You will be asked to enter your password twice.
- The computer will print many lines of text. At the bottom of the text there should be a green prompt that looks like username@otherstuff. Type exit to leave the Ubuntu system.
- Type wsl --set-default Ubuntu-24.04 The computer should print that the operation was successful.
Install Java
- Type wsl This is the command that will use to start the Windows Subsystem for Linux.
- Type sudo apt-get update this makes sure that we have the most current version software in the subsystem (including Java). There will be a lot of updates listed.
sudo
means that this is an administrator task, you will be asked for your password (The one you created when installing Ubuntu.) - Type sudo apt install default-jdk If you did this quickly enough you will not have to re-enter your password. It will list all the things that it needs to install.
- Type Y when prompted.
- Type java -version and verify that it installed version 21.0.3 If not, type sudo apt install openjdk-21-jdk
- Type exit to exit the Windows Subsystem for Linux.
- Type exit again to close the command window.
Modify .bashrc file
Here we will add a line to the .bashrc
file so that each time we start WSL, it will change to our course directory.
- Type nano .bashrc to edit the
.bashrc
file - Page down to the bottom of the file
- Add a line with the following cd /mnt/c/Users/[username]/csc1110 where
[username]
is your Windows username (e.g.,cd /mnt/c/Users/taylor/csc1110
) - Type CTRL-x, then y when prompted to "Save modified buffer?" and enter to accept the
.bashrc
filename
Creating a folder/directory for the course
Following directly from the previous instructions to modify the .bashrc
file...
- Type cd /mnt/c/Users/[username] (where
[username]
is your Windows username) - Type mkdir csc1110 to create a folder/directory for this class. (make directory)
- Type cd csc1110 to change into that folder/directory. (change directory)
- Start the Nano text editor by typing nano FirstProgram.java
- Type the following text in the text editor:
public class FirstProgram {
public static void main(String[] args) {
System.out.println("It worked");
}
}
- Type CTRL-x to exit Nano (say yes to the prompt to save and keep
FirstProgram.java
as the filename). - Type ls to list all of the files in the directory. (list) You should see the
FirstProgram.java
file listed. - Type javac FirstProgram.java to compile the program. (javacompile)
- Type ls to list all of the files in the directory. You should see
FirstProgram.class
added to the list of files. - Type java FirstProgram to run the program. You should see
It worked
displayed.
Useful Commands
nano
— Text editorjavac
— java complier, e.g.,javac Test.java
createsTest.class
, the compiled version of the Java program.java
— Runs a program in the Java Virtual Machine, e.g.,java Test
runs the program in theTest
class.ls
— list files in directory/foldercd
— change directory, e.g.,cd csc1110
to change into thecsc1110
directory.cd ..
to change into the directory one level up.
mkdir
— make directory, creates a new directoryrm
— remove, e.g.,rm Test.java
removed (deletes) theTest.java
file in the current directory.mv
— move, moves/renames a file, e.g.,mv Test.java Program.java
changes the name ofTest.java
toProgram.java
.