Saturday, 3 March 2018

How to make Windows go Linux with Cygwin

If you still think that operating systems are tied to hardware, you need to update your thinking; nowadays there are lots of options that let you run one operating system within another or in parallel to another. This is true whether your base operating system is Linux, Windows or macOS X. My main system boots macOS X, for example, but also has Windows 10 and Ubuntu Linux accessible as full operating system installs.

This requires a lot of resources, however, and is typically done as a dual boot or virtual machine, which can put a lot of demands on your computing device. Certainly if you’re running apps within a VM while trying to use other programs in the native operating system, you might end up frustrated with overall performance.

But there are some smart alternatives that graft features and characteristics of one operating system onto another. Cygwin offers just this ability to anyone who is running Microsoft Windows but wants access to a Linux command shell and many of the best open-source Linux programs available today. Better yet, as an open-source project, Cygwin is free to install and use.

At a more technical level, Cygwin is a brilliant idea, an emulation of all the API-level calls required for POSIX (Portable Operating System Interface) compliance between Linux and the Windows system. This means that you instantly have support for a wide variety of development tools and utilities that otherwise aren’t a part of Windows itself. Particularly for developers, this can be a huge boon.

Let me be clear, though: Cygwin does not offer the ability for you to download and run any Linux application. Apps need to be recompiled specifically for the Cygwin environment to work properly. Good news, though; there are lots and lots of open-source software packages — over 21,000 — that have been ported to the Cygwin environment, notably including ImageMagick, Python, Perl, Ruby, EMACS, make, curl and bzip2, along with support for developing code in C, C++, Objective-C, Tcl, Ada, CLISP, Scheme and Prolog.

Not only that, but you can run the X Window System within Microsoft Windows with Cygwin too, through the Cygwin/X port of the venerable windowing system. Why you’d do that is a separate question to consider, but it’s a good demonstration of the power and flexibility of adding Cygwin to your Windows machine.

Getting started with Cygwin
The installation process is remarkably easy; simply go to cygwin.com and click on the install link. As is typical with the open-source community, however, you are then prompted to choose specific packages to install out of the 21,000-plus available, which can be a bit overwhelming. Choose the default packages, and a Cygwin terminal will show up on your desktop after a burst of downloads and compiles.

cygwin install

That’s it. To add additional packages after the install, simply relaunch the installer and choose what you’d like included. Don’t be surprised if the selection of a single package involves downloading and building a dozen or more dependencies, other packages or libraries required for the main package to be successfully installed and executed.

The entire library and code set for a C development environment is installed by getting “gcc-core,” and once that’s done, you can start writing, compiling and executing C source code within the Cygwin environment itself within Windows. Consider the following example of a rudimentary C “hello world” program compiled and executed:

cygwin demo c helloworld


While there’s unquestionably a lot to the GCC compiler installation behind the scenes, the entire developer subsystem took just a few mouse clicks of actual administrative work to install.

There are lots of other packages you can install, too, as desired, including the aforementioned X Window System, K Desktop Environment, GNOME, an Apache web server and system daemons such as sshd (which allows your system to accept ssh secure shell connections). You can even install a version of OpenOffice if you want to have a Microsoft Office-like environment within Windows but through the Cygwin open-source lens.

Looking more closely at Cygwin packages
If you’re not familiar with the world of Linux and Unix systems, every software app or package listed above is going to be incomprehensible, so let’s have a closer look at each:

X Window System. Long before there was Microsoft Windows, there was a team of developers at MIT working on adding a graphical user interface to the command-line-heavy Unix environment. The design goal was to create a flexible, layered GUI that not only let the windowing system run on a wide variety of Unix systems, but also supported networked computing: Some windows on a computer would actually be from processes hosted on other computers, and some processes on the local computer could be controlling windows elsewhere online. This became The X Window System, and it proved quite powerful and revolutionary.

GNOME and K Desktop Environment (known more informally as KDE). Two of the most popular window managers that exist atop X Window System. Without a window manager, you don’t get background graphics, frames around windows, control buttons such as “close and “minimize” and popup menus. GNOME and KDE are competing visions of how the graphical interface should look, but at a base level, they offer the same functionality, and X is vastly more useful and powerful with a modern window manager added.

Apache web server. If you go online, you probably bump into Apache all the time. One of the original web server programs, it now powers quite a lot of websites. Its name is a play on words: a patchy web server.

sshd. This and other system daemons (as they’re called) are the low-level programs that run behind the scenes and help keep the internet moving along, too; ssh, the secure shell, is an easy way to allow remote users to log in to a computer through an encrypted connection. No graphics, no windows, nothing fancy, just a command line and all the power that implies. Other system daemons include the network time server, FTP and SFTP file servers and email servers.

OpenOffice. This terrific open-source suite of programs offers just about all the features and functionality of Microsoft Office, but without the big price tag. In fact, without any price tag. Sure, you can use Google Docs, but do you want Google keeping a copy of every document you write and spreadsheet you update? That’s why OpenOffice is a great alternative. Bonus: for Windows and Mac systems, too, if you don’t want to run the Cygwin/Linux version.

Alternatives to Cygwin
Not sure you want to run Cygwin on your Windows computer? There are many alternatives to explore, including Microsoft’s Windows Subsystem for Linux (WSL), dual booting and VM solutions.

Most developers have moved on from Cygwin, too, at this point. Steve Hulet, CTO of FreshConsulting.com, says, “Cygwin was super helpful back in the day, but I feel there are better options now.” This sentiment is echoed by Max Galka, a developer at Elementus: “Since upgrading to Windows 10 a year or so ago, I have been using the Windows Subsystem for Linux instead, which has made my life a lot easier.”

Because it’s from Microsoft, Windows Subsystem for Linux plays very well within the Windows world. As Microsoft says, “Now you can install and run Ubuntu, openSUSE, and SUSE Linux Enterprise Server alongside one another, and alongside all your favorite Windows tools, and shells including Cmd and PowerShell.”

For some developers, it might make a lot more sense to explore a dual-boot environment, where both Linux and Windows are installed on different partitions of the same boot drive. At boot time you select which operating system and environment you want to launch into. One significant benefit of this is that it’s a much more secure strategy, because viruses or other malware cannot migrate from one environment to the other.

Most major Linux distributions support dual-boot configurations, using GNU GRUB as the program that lets you determine at boot time which OS you want to run. For dual booting, you’ll want to do research on optimal partition sizes to ensure that neither OS is cramped or runs out of space.

Then there’s the VM approach, a system that lets you run an entire operating system as an application running within another OS. My MacBook Pro, for example, runs Ubuntu Linux and Windows 10 within VMware Fusion. There are both commercial and open-source VM solutions for a Windows base, including VMware and Virtual Box from Oracle.

Not everyone is a fan of these alternative solutions, however. Aaron Yoshitake, founder of PIckAKit.com, says that Cygwin is an important part of his development environment and that “[Cygwin] has its pluses and minuses, but I prefer it to running a Ubuntu VirtualBox VM.”

Finally, there’s Winelib, part of the open-source Wine project, which lets you run Windows programs within Linux- and Unix-like systems. It’s the inverse of Cygwin. The full Wine system supports executing unmodified Windows binaries.

https://www.computerworld.com

No comments:

Post a Comment