SEARCH

How-To Geek

How to Use Linux Commands in Windows with Cygwin

Windows command-line tools have advanced a lot with PowerShell, but Linux has had a much more usable terminal for many years. Here’s how you can get the best of both worlds with Cygwin, a ‘nix-style terminal for Windows PCs.

In today’s lesson, we’ll explain how to get Cygwin running, but stay tuned for future articles where we’ll explain how to use it for all sorts of different things.

Install Cygwin

Cygwin comes with a normal setup.exe to install in Windows, but there are a couple steps you will need to pay attention to, so we will walk you through the installation.

To keep the installation small while saving bandwidth for you and Cygwin, the default installer will download only the files you need from the internet.

The default install path is C:\Cygwin but if you don’t like to have programs installed on the root of your C: drive you can change the path or make a symbolic link from C:\Cygwin to your program files.

Click next until you come to a download mirror selection. Unfortunately, the installer does not say where the mirrors are located so in most cases you might as well just guess which mirror works best.

After you have selected a mirror, the installer will download a list of available packages for you to install. Here is where things get a bit more intimidating.

There will be hundreds of packages available separated by multiple different categories. If you don’t know what the package is you can leave the default selection and install additional packages later by running the installer again.

If you know what package you need, you can search for it and the results will be automatically filtered.

Once you click next, it will take a little while to download all the selected tools and then finish the installation.

Add Cygwin Path to Windows Environment Variable

After the installation you will have a Cygwin icon on your desktop that you can launch to open the Cygwin terminal.

This terminal starts in the C:\Cygwin\home\<user> folder but that isn’t particularly useful because you probably don’t have any files stored there. You can use all of the basic Linux commands but if you want to get back to your C: drive you have to change directory to /cygdrive/c.

To make Cygwin work in your normal Windows command prompt you need to add Cygwin to your Windows Environment Variables.

Start by opening your system properties with either Win+Pause/Break or right click on computer and select properties.

In the left column click on advanced system settings to open the system properties window we are looking for.

From the advanced tab, click on environment variables at the bottom.

Then in the system variables, locate the path variable and click edit.

At the end of the variable value option, add the Cygwin bin location like so.

;C:\Cygwin\bin

Note: Make sure you add a semicolon to separate it from the other values.

Click OK to close out of the window and then open a command prompt to test out a few Linux commands.

As you can see from the below picture both pwd and ls work in the normal Windows command prompt. You can also see that /cygdrive/c is automatically added to the location.

There is a lot more you can do with Cygwin installed and we will show you some more of the useful tools in future articles.

Cygwin homepage

Justin is a Linux and HTPC enthusiast who loves to try new projects. He isn't scared of bricking a cell phone in the name of freedom.

  • Published 01/25/11

Comments (10)

  1. Lorannais

    Hi ! Big tips, thank’s ;)

    But what about x64 version ?

    ;)

  2. JJ

    I remember installing this for a project on uni. It took ages and the installer is very unclear, but once it is running..

  3. ronind200

    Thanks for the article! Cygwin documentation never explains everything very clearly. Another good article would be how to cleanly remove Cygwin. That always feels really messy.

  4. squeek

    How about using mobaxterm as an alternative which requires no install. Cygwin is intergrated into it.

  5. Anish Sane

    I need some help.
    I have installed CygWin on my windows system & then ssh server on it. (Using the same setup.exe from cygwin)

    Now I want to connect to this system from another system using ssh with X windows support.
    I am able to ssh. but that window is showing up on the 1st pc only. i.e. X11 forwarding is not happening.
    I believe I have set up /etc/sshd_config correctly in cygwin.

  6. Kevin Scott Schlanger

    I was looking for something like this yesterday. And when I was checking my subscribed feeds, here it is!

  7. Horses4Courses

    I don’t think “more usable” is a good description. More useful, more complex, more feature-rich, more illegible (dark blue text on a black background, anyone?) perhaps but it’s less usable, if you ask me. I also note that your examples use “ls” and “pwd”, not exactly worth the hassle of installing cygwin for those. Perhaps someone could add some good reasons why you might actually want to install and use cygwin (that could not more easily be accomplished with Perl or Powershell or even VBS).

  8. LinuxRocks

    Thanks for the help. This information is very useful. It took me a day to find a way to run unix commands on windows. But finally this web page helped me in succeeding. Thanks a lot.

  9. Naarayana

    hi sir ,is this working for all commands.in my pc some commands is not working like VIEDITOR,
    ,,,,,,,,,,,,,PLZ GIVE ME THE REPLY,,,,,,,,,,,,

  10. saumya

    thanks buddy… very easy understanding…

Enter Your Email Here to Get Access for Free:

Go check your email!