As a developer, you’re likely to find yourself split between using Windows in order to access all the tools, games, and software that come with it or using Linux, which is particularly ideal for developers. If you have a single computer, you’ll have to pick one operating system.

If you want to use two operating systems, you either have to dual boot, which is risky and complex, or use a virtual machine which can create performance overhead. Luckily, there’s a way to avoid choosing either of the two operating systems. Why pick when you can easily have both?

How to Use Linux Commands on Windows

The Windows operating system allows you to leverage the power of Linux and Windows all from the same machine. From Windows, you can run Linux applications and Linux commands. The ability to run Linux commands from Windows is a game changer.

First, it allows you to have the best of two operating systems from one machine at no cost. You’ll be able to access all the software that comes with Windows and leverage its beautiful design and user-friendliness while still enjoying the power of the Linux command line. This allows you to automate tasks, work with various open-source tools, and access Windows files and executables directly from a bash shell.

Additionally, running Linux commands on Windows will allow you to easily install and manage your software using Linux package managers; you’ll be able to easily work on cross-platform projects and access Linux utilities such as SSH, grep, sed, and awk.

Finally, using Linux commands from Windows provides a more gentle introduction to Linux for Windows users, making it easier to transition to fully using the Linux operating system in case you need to. The tool that allows you to run Windows on Linux is the Windows Subsystem for Linux.

Windows Subsystem For Linux (WSL)

YouTube video

The Windows Subsystem For Linux (WSL) is a Windows feature first released in 2016. WSL allows you to install a real Linux distribution directly on Windows and run the Linux file system, command line tools, GUI applications, and utilities directly on Windows without installing a virtual machine or dual boot Linux and Windows.

To use WSL, you need to be running Windows 11 or  Windows 10 version 2004 and higher, with build 19041 and higher. WSL supports x64 and Arm CPUs.

WSL allows the installation of Linux distributions such as Ubuntu, OpenSUSE, Kali, Debian, Fedora, Fedora remix, and Arch Linux. All these distributions are available for installation from the Microsoft Store.

With WSL, you’ll have an integrated Linux experience on Windows such that you can invoke Linux executables from Windows and view Linux files from Windows. You can also invoke Windows executables and access Windows files from the Linux Bash Shell.

How the Windows Subsystem For Linux Works

How-the-Windows-Subsystem-For-Linux-Works-1

Behind the scenes, WSL is not an emulator or virtualizer. WSL acts as a compatibility layer sitting between Windows and Linux. Technically, WSL allows you to run unmodified ELF64 Linux binaries, thus providing an integrated experience.

To do this, WSL provides a Microsoft developed, Linux kernel interface that sits on top of the Windows Kernel. This Linux kernel runs inside of Windows and is built on the core technology of Hyper-V.

Hyper-V is a native hypervisor that is software that can create and run virtual machines. Hyper-V provides hardware virtualization, which means that virtual machines run on virtual hardware. WSL being built on the core technology allows it to provide improved file system performance and better Linux Application support.

To run unmodified ELF64 Linux binaries, WSL translates Linux systems calls from Linux binaries into Windows System Calls for them to be executed at native speed.

On the Linux kernel interface running on Windows and provided by WSL, different Linux distributions can be installed. These distributions provide a container-like environment with all dependencies and package management needed to run Linux applications. Linux applications run within these distributions.

Why Use The Windows Subsystem For Linux?

Why-Use-The-Windows-Subsystem-For-Linux

If you have used a virtual machine to run Linux on Windows before, you might be wondering what WSL has to offer you that a virtual machine can’t. Well, for a start, WSL uses fewer computer resources than running a virtual machine.

WSL uses way less storage and memory and does not have a large footprint on your CPU usage like a virtual machine. WSL also allows you to access your Windows files from Linux, a feature that allows you to use Linux command line tools on the same files you use your Windows application on.

Another key feature of WSL is how easy it is to run Linux. Virtualization can be complicated, and WSL avoids all of that. Additionally, it makes it easy to install a variety of Linux distributions and also to change from one Linux distribution to another.

To developers, WSL allows you to enjoy the best of two worlds. You can run Linux and have access to all the unique programming tools and open-source resources developed with Linux in mind, while still enjoying all the features that come with Windows.

With WSL, you won’t run into compatibility issues because you’re using tools that only run on Linux. Additionally, switching between the two operating systems will be much faster and easier and won’t require a complicated setup or an extra computer.

To get started using Linux commands, an easy way to start is to Install Windows Subsystem For Linux on your machine.

How to Install Windows Subsystem for Linux

1. Confirm your computer meets the following requirements: it should be a 64-bit running Windows 11 or Windows 10 version 2004 and higher. The Windows 10 version should be built 19041 and higher. Make sure you are connected to the internet.

2. Open the start menu, search for Powershell, and select Run as administrator to open with administrator privileges.

powershell-admin

3. On the open PowerShell enter the following command

wsl --install

The command will enable all the features needed to run WSL and make any updates that your operating system might need to run WSL seamlessly. First, a virtual machine platform platform will be installed, and then finally, WSL will be installed. Be patient as this can take a while.

installing-WSL

4. Once the process completes, you can confirm WSL has been installed by running wsl –install again. In case you see a help page for WSL as shown below, the installation was successful.

wsl-installed

5. The next step is to install a Linux distribution to use with WSL. To see all the available distributions that can be installed, enter the following command into PowerShell

wsl --list --online

You’ll get back a list of available distributions as shown below:

linux-distros-available

6. From the list, you can install any Linux distribution you want by entering

wsl --install -d <distribution NAME>

For instance, to install Ubuntu 22.04 Long Term Support, execute the following command:

wsl --install -d Ubuntu-22.04
installing-ubuntu

Wait for the process to finish. You’ll then be presented with a message for successful completion an Ubuntu terminal window will open as shown below:

unix-username

Enter your username and password to set up your Environment. Remember, with Linux, when you enter your password in the terminal, you won’t see any characters as you type. However, your input is still captured.

An alternative to installing a distribution from Powershell is to open Microsoft Store and Search for WSL. You’ll be presented with all available distributions. Click Get to install your desired distribution

get-linux-distro-

7. After entering your username and password, you’ll be able to access Ubuntu on Windows as shown below:

start-using-ubuntu

Feel free to start using your favorite Linux commands.

Your installed Linux Distribution can easily be found from the start menu any time you want to open it

how-to-find-your-linux-distro

In your file explorer, you’ll also notice a new storage location called Linux, where all your distributions and Linux files are stored.

linux-in-file-manager

Windows Subsystem for Linux is an excellent way to run Linux commands on Windows. In case you are unable to install WSL on your machine, probably because your computer does not meet the requirements needed to install WSL, there are excellent alternatives to WSL that you can install. Let us look at two emulators that can help you run Linux commands on Windows.

Use Linux Commands on Windows using Cygwin

Cygwin is a large collection of GNU and Open Source tools which together provide functionality that is similar to that of a Linux distribution on Windows.

Cygwin is a UNIX emulator and provides a UNIX shell environment on Windows giving you access to a variety of tools from the Linux ecosystem. 

As their tagline states, Cygwin aims to provide a Linux feeling on Windows. However, Cygwin does not allow you to run Linux applications on Windows. Cygwin works with all x86_64 versions of Windows, starting from Windows 7.

To install Cygwin:

1. Navigate to their installation page download the setup-x86_64.exe file and run it

Cygwin-install-page-1

2. Go through the first few screens on the installation wizard screen, clicking Next to keep the default selections. This will keep the Download source to Install from the internet, use the default suggested root and package directory, and use the System Proxy Settings.

3. When it comes to choosing a site from which to download Cygwin packages, click on any of the provided links the click on Next.

download-sites-cygwin-6

4. When selecting the packages to install, keep the default section. That is Under view; make sure it is Category that is selected then click on Next. This will take you to the review and confirm changes screen. Click on Next to start installing Cygen.

install-default-cygwin-7

5. Wait for the installation process to finish.

installation-cygwin-9

6. Click on Finish to complete the installation process. You can uncheck the boxes in case you don’t want to create a Cygwin icon on the Desktop and the Start Menu.

finish

7. You can find Cygwin’s icon on the start menu or on the Desktop. Double-click to launch Cygwin

Termina-Cygwin-open

8. Cygwin will open with a bash shell window where you can start using Linux commands just like you were on a Linux machine.

use-the-terminal

Use Linux Commands on Windows using QEMU

QEMU is a generic and open-source machine emulator and virtualizer. QEMU is commonly used as a system emulator where it provides a virtual model of another machine where you can run a different operating system from the one you are on.

To install QEMU, 

1. Go to the downloads page and download the qemu setup .exe file for 64-bit computers and run it once the download is complete

QEMU-downloads-page

2. You’ll be presented with the QEMU setup wizard window. Click Next to proceed. In the next screens, agree to the license agreement, click next to install the default selected components, and select your installation location or leave the default selected Local disk C. For simplicity, do not change your installation location

qemu-welcom-screen

3. Wait for the installation to complete and click Finish.

qemu-installation

4. The next step is now adding the file path to where QEMU was installed to our environment variable. To do this, navigate to My Computer -> Local Disk C -> Program Files -> qemu as shown:

file-explorer-qemu

5. Highlight and copy the file path to where QEMU is installed in your machine

file-path-windows

6. Open Windows Settings, click on System, scroll the left menu bar, and select About. In the About page click on Advanced system settings to open the System Properties window

windows-about-page-advance

7. In the System Properties Window in the Advanced tab, click on Environment Variables

System-Properties-Windows

8. On the Environment Variables page, double-click on Path, to add the path where QEMU was installed.

path-variables

9. Click on New then paste in the path URL you copied and click on Okay to add it. Click on Okay on the Environment Variables Windows and System Properties windows to save the changes and close the windows.

add-environment-variable

10. To confirm QEMU was successfully installed and its path successfully added to the environment variables, open PowerShell and execute the following command:

qemu-img --help

In case both processes were a success, you’ll see such a window showing the version of the qemu-img installed and its help page.

qemu-help-menu

11. To start emulating a Linux operating system, you’ll have to download the .iso image of the Linux distribution you want to emulate using QEMU. Then, from Powershell, navigate to the storage location of the .iso file and execute

qemu-system-x86_64.exe -boot d -cdrom <linux_distro_name> -m <RAM_TO_ALLOCATE>

To emulate Ubuntu 22.04.3 from an iso file I have downloaded, I’d navigate to where the .iso file is located and execute:

qemu-system-x86_64.exe -boot d -cdrom ubuntu-22.04.3-desktop-amd64.iso -m 2048

This will open a bash shell window where you can start using Linux commands.

Conclusion

When using Linux on Windows, it is important to keep in mind that while you can access Windows files from Linux and vice versa, file paths may need adjustments.

Some OS-specific commands may not also work as expected, file permissions between the two operating systems are handled differently, and you’ll need to handle resource allocation for the two systems to ensure both have enough to run seamlessly. Additionally, make sure to always back up your important files in case anything goes wrong.

You may also explore WSL2 Capabilities, the installation process, and how to use it effectively.