HowTo |
Use UNIX Emulators on Windows | Prof. Bartenstein |
If you have a Windows laptop, there are UNIX emulators that make it possible to do the coding work for this class on your laptop.
(If you have an Apple computer, e.g. a Mac, then MacOS is already directly related to UNIX, so has most of the capabilities you will need, including a terminal window and a shell. You may need to install tools such as git on a Mac. Here's a Mac Git Download web page with some options to try. Unfortunately, I don't have any Apple hardware, and cannot help out with Mac problems very well.)
A Unix emulator provides the capability of opening a terminal window on your laptop that looks and feels like a terminal window on a UNIX machine. You get a command line with a prompt where you can type commands. The response to those commands is typed back to the screen and another prompt appears. The default disk space in your UNIX emulator will be a sub-directory of your windows disk. That means that you can use either UNIX commands such as "ls" to list the contents of that directory, or you can use Windows Explorer to look at the same list of files. You can edit files using a windows editor such as Notepad, and those edits will be visible in your terminal window.
In a real UNIX terminal window, there are commands for tools such as editors or web browsers which open up full screen applications in separate windows. Many emulators do not support full screen applications, or if they do support full-screen, it takes lots of extra effort which frankly is not worth it. If full screen is not supported directly, you can oftgen run Windows commands from a UNIX emulator terminal window which run in full screen. For instance, there is a Windows version of gedit that you can install on Windows, and make available to the UNIX emulator so you can invoke gedit from the terminal emulator.
There are three good UNIX emulators that run in a Windows environment, WSL, Cygwin and git-bash. There may be other alternatives as well; new software is always becoming available, but WSL, Cygwin and git-bash all have the advantage of being free to install, relatively easy to use and maintain, and which provide all (or most of) the tools necessary to do work for Computer Science classes.
The following table highlights the advantages and disadvantages of the three top options.
| WSL | Cygwin | git-bash | |
|---|---|---|---|
| Advantages | Full Linux capability, supports full screen, configurable to come close to SoC environment. Good IT experience. | Traditional Windows UNIX emulator. Also configurable, but not as much as WSL. | Minimal emulation, easiest to install. |
| Disadvantages | Most maintainence required. Major updates take a long time. | Not as flexible or extendable as WSL. Support of full-screen apps is available, but more trouble than it's worth. Less formal support compared to WSL. Some applications, such as valgrind, are not supported. | Inflexible. Does not support multiple versions of tools. No full-screen app support. |
The following Microsoft web page How to install Linux on Windows with WSL has complete details on installing WSL. I use WSL version 2, and I am running Ubuntu 22.04.5, and I have used sudo apt get app to get whatever is not there by default - for example, valgrind.
The git-bash tool contains a very basic UNIX emulator. The primary purpose of git-bash is to enable Windows users to use the "git" tool, which is used to keep track of multiple versions of software projects. We are not using the git tool to manage our software in this class, but along with git, when we install git-bash, we get a terminal emulator which is very useful.
Since git-bash is relatively small, installing git-bash is pretty simple.
Note that git-bash does not include a full-screen editor (it does include "vi" which is a command line editor, but "vi" is not easy to use.)
Note also that git-bash does not include the compiler (gcc), the debugger (gdb), and the make commands we will need for this class. These need to be installed separately. See #Installing MingW for details on how to get these tools and make them available in your git-bash terminal window.
Double click on the Git Bash icon to open a git-bash terminal window. git-bash will open a terminal window titled "MINGW64...", which stands for "Minimum Gnu for Windows 64 bit". Your "home" directory will be your standard Windows user directory, namely C:\Users\userid, where userid is your Windows user id.
You can use all the standard UNIX commands, such as ls, mkdir, cd, pwd, and cat. You can access your U drive (if you have it mounted) by using the specification "/u". You should also be able to use all the git commands such as git clone, git commit, git push, etc.
If you are in a class that works with the C language, once you have installed MingW on your laptop and updated your Path variable (see MingW Installation you can invoke the gcc editor, the gdb debugger, or the make command in exactly the same way you would in a UNIX environment.
One detail you need to be aware of. When you run the gcc compiler, it will produce a binary executable file as an output. For instance, if you run the command gcc -g -Wall -o hello helloWorld.c, in the UNIX world, gcc would produce an executable file called hello with no filetype. You could then type ./hello to run this command. When you run the gcc command in a UNIX emulator, the UNIX emulator knows it is running in a Windows environment, and writes an executable file called hello.exe. The gcc command adds the ".exe" file type to tell Windows this is an executable file. However, when you go to run the command ./hello, the UNIX emulator looks FIRST for an executable file called hello in the current directory. If it doesn't find one, it looks for a file called hello.exe, and runs that.
Normally you wouldn't care that under the covers that the UNIX emulator added the .exe filetype to your file. However, if using your U drive, and you have compiled on a real UNIX platform, then there will be a file called hello in your directory that will work on a real UNIX platform, but will not work in the UNIX emulator. Even though you compiled from within the UNIX emulator and created the file hello.exe, the emulator still tries to run hello first, and fails with an error message. Fix this problem by either deleting the hello file using the command rm hello, or by invoking hello using the command ./hello.exe to explicitly run the version of the executable file with the .exe filetype.
javac --version to verify the level of the compiler, and java --version to verify the level of the Java Run Time Environment (JRE) that you have available.You can cut, copy, and paste from or to the git-bash terminal window, but the shortcut command Ctrl-C, Ctrl-X, and Ctrl-V will not work. The terminal emulator doesn't want UNIX cut copy and paste to get confused with Windows cut copy and paste. I always right mouse in the git-bash terminal window when I want to do a cut, copy, or paste instead of using shortcuts.
The git-bash terminal window is configurable. Go to the title bar that has a git-bash icon and says "MINGW64" on the left side, and right click on that icon to see the options you have. You can change the default size, fonts, background and foreground colors, etc. etc.
There are two major parts to Cygwin - a setup tool and the emulator itself. The setup tool is a full screen windows application that steps you through the process of configuring, downloading, and building the emulator itself. There are millions of configuration choices with Cygwin, so its nice to have a full-screen application to walk you through the process.
Note that if run the setup tools the first time to make the Cygwin emulation tool, and then realize you want to change some configuration choices, you can re-run the setup tool. The setup tool remembers your first choices and only downloads the new things it needs before rebuilding your Cygwin emulator.
On the "Select Package" screen, there is a "View" button with a pull-down list of options. I like to start with "Category" selected. If there is a "+" in the box next to "All", click on it, and you will get a list of categories. Then expand the "Devel" category. You will need to select the "gcc-core" package, the "gdb" package, and the "make" package, which all appear in the "Devel" category. You may want to install some other packages, or you may want to get a feel for things as they are, and if you need something later, you can always re-run the setup tool.
The Cygwin install process created (by default) a subdirectory on your Windows hard disk at "C:\cygwing64". You can look at this using Windows Explorer by going to "This PC", and then going to you C: disk, and then the "cygwin64" subdirectory.
Double click on the Cygwin64 Terminal icon (or Cygwin Terminal icon) to open a Cygwin terminal window. Your home directory will be on your windows drive "C:\cygwin64\home\userid", where userid is your Windows userid.
You can use all the standard UNIX commands, such as ls, mkdir, cd, pwd, and cat. Since you have chosen the gcc-core, gdb, and make packages, you will also be able to run the gcc command, the gdb command, and the make command. You can access your U drive (if you have it mounted) by using the specification "/cygdrive/U". You should also be able to use all the git commands such as git clone, git commit, git push, etc.
One detail you need to be aware of. When you run the gcc compiler, it will produce a binary executable file as an output. For instance, if you run the command gcc -g -Wall -o hello helloWorld.c, in the UNIX world, gcc would produce an executable file called hello with no filetype. You could then type ./hello to run this command. When you run the gcc command in a UNIX emulator, the UNIX emulator knows it is running in a Windows environment, and writes an executable file called hello.exe. The gcc command adds the ".exe" file type to tell Windows this is an executable file. However, when you go to run the command ./hello, the UNIX emulator looks FIRST for an executable file called hello in the current directory. If it doesn't find one, it looks for a file called hello.exe, and runs that.
Normally you wouldn't care that under the covers that the UNIX emulator added the .exe filetype to your file. However, if using your U drive, and you have compiled on a real UNIX platform, then there will be a file called hello in your directory that will work on a real UNIX platform, but will not work in the UNIX emulator. Even though you compiled from within the UNIX emulator and created the file hello.exe, the emulator still tries to run hello first, and fails with an error message. Fix this problem by either deleting the hello file using the command rm hello, or by invoking hello using the command ./hello.exe to explicitly run the version of the executable file with the .exe filetype.
You can cut, copy, and paste from or to the Cygwin terminal window, but the shortcut command Ctrl-C, Ctrl-X, and Ctrl-V will not work. The terminal emulator doesn't want UNIX cut copy and paste to get confused with Windows cut copy and paste. I always right mouse in the Cygwin terminal window when I want to do a cut, copy, or paste instead of using shortcuts.
The Cygwin terminal window is configurable. Go to the title bar that has a terminal icon and says "bash" on the left side, and right click on that icon to see the options you have. You can change the default size, fonts, background and foreground colors, etc. etc.
If your emulator does not support full-screen applications, you will need to use a Windows editor instead. There are several different editors you can use in a Windows environment, all that can be invoked from a terminal emulator window if you have them set up correctly. Some of these are even packaged with Windows, so you don't need to install them. Your choices include the following (this is by no means a complete list, but these are the interesting ones I know of.):
The major advantage of VScode is that it does more checking on your code in the editor environment. This allows you to find and fix problems in your code earlier. If this is important to you, I would suggest using VScode primarilly as an editor. Do not use VScode build/run features, and do not use VScode remote features. You may choose to run VScode locally. It is possible to run "make" and "gdb" and even run commmands in a local VScode "terminal" if your machine is configured correctly. However, once you complete your code, FTP it to an LDAP machine, and rerun there.
I've installed and used most of these editors in my career, but would recommend gedit as the easiest, most intuitive, and sufficiently powerful and productive to do everything we need to do in this class.
These instructions are out of date... there is a free version of gedit for Windows, but this version now charges a license (sorry)
The gedit editor is free software, one of the components of software built by the "gnome" organization (See https://www.gnome.org for more details.). Many of the UNIX based systems around campus use gnome software for a UNIX desktop and tool suite, so students are often familiar with the gedit editor.
Download the gedit install package by going to https://download.gnome.org/binaries/, and choosing the platform that matches your laptop, and then choosing the "gedit" folder. Download the ".msi" (Microsoft Install) file, and double click on it. This will take you through the gedit install process. This will not make a new desktop icon, but that's OK. We won't be invoking gedit from the desktop, but from our UNIX emulator terminal window via the command line.
In order to invoke from the command line, we need to tell Windows where to find our newly installed gedit command. In order to do this, we need to update the Windows "PATH" variable. Do this by:
Now you should be able to run "gedit filename" from the UNIX emulator terminal window.
One note... The first time you invoke gedit from a terminal window, make sure you add an ampersand (&) to the end of the command so that gedit can "run in the background"... in other words you can run the editor and the command line window at the same time.
Once gedit is up and running, the next time you invoke gedit for a different file, it does not start a new gedit window... it just sends your new file to the existing gedit window which is already running in the background. The existing gedit window will open a new tab for the new file. For this reason, you don't need to run the second invocation in the background (although runnning it in the background won't hurt anything.
When you close your editor, the next time the terminal window updates, you will see a message such as [1]+ Done gedit hello.c to indicate that the background job has finished.
MingW stands for "Minimal GNU for Windows". This is a package that contains several GNU tools ported into a Windows environment, including the GNU C compiler (gcc), the GNU debugger (gdb), and the GNU make command (make), all of which we need for this course. MingW can get complicated, but we need only the simplest installation. The following instructions descrdibe how to download and install the basic MingW pacakge we will be using.
Now that you have installed MingW, you need to add MingW to your path so that git-bash can find the tools in MingW. Add to your path by doing the following steps...