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?
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)
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
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?
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.
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.
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.
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:
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
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:
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
7. After entering your username and password, you’ll be able to access Ubuntu on Windows as shown below:
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
In your file explorer, you’ll also notice a new storage location called Linux, where all your distributions and Linux files are stored.
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
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.
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.
5. Wait for the installation process to finish.
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.
7. You can find Cygwin’s icon on the start menu or on the Desktop. Double-click to launch Cygwin
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 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
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
3. Wait for the installation to complete and click Finish.
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:
5. Highlight and copy the file path to where QEMU is installed in your machine
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
7. In the System Properties Window in the Advanced tab, click on Environment Variables
8. On the Environment Variables page, double-click on Path, to add the path where QEMU was installed.
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.
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.
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.
-
EditorNarendra Mohan Mittal is a senior editor at Geekflare. He is an experienced content manager with extensive experience in digital branding strategies.