Install Cygwin Packages

Photo by LUM3N on Unsplash

Install Cygwin Packages

Simplify package installation and uninstallation in cygwin terminal

What is Cygwin?

Cygwin is a collection of open source tools that allows source code designed for Unix-like operating systems to compile and execute in Microsoft Windows OS.

Setup the system

You can download the installer from this link. You need to remember the location of installer (recommended C:\cygwin_installer) which is referred in next section.You can follow the steps in this video to install it in your windows OS.

Note: You need to install Cygwin in your windows system to follow next section.

Variable NamePath in WindowsPath from Cygwin terminal
CYGPATHC:\cygwin or C:\cygwin64
INSTALLERPATHC:\cygwin_installer/cygdrive/c/cygwin_installer
CYGINSTALLERsetup-x86.exe or setup-x86_64.exesetup-x86.exe or setup-x86_64.exe

Open cygwin terminal from windows search box. Steps to directly access CYGINSTALLER from cygwin terminal.

  1. Change current working directory to home directory cd ~.

  2. Create a bin directory inside home directory mkdir bin.

  3. Move to bin directory cd ~/bin.

  4. Create a softlink of cygwin installer inside bin directoryln -s INSTALLERPATH/CYGINSTALLER (use paths for cygwin terminal like ln -s /cygdrive/c/cygwin_installer/setup-x86_64.exe).

  5. Verify the softlink created for CYGINSTALLER ls -l.

  6. Change current working directory to home directory cd ~.

  7. Open .bash_profile file using any text editor and uncomment code snippet given below. In cygwin version 2.897, the code is present in line number from 32 to 34.

# Set PATH so it includes user's private bin if it exists
if [ -d "${HOME}/bin" ] ; then
  PATH="${HOME}/bin:${PATH}"
fi
  1. Update the path source .bash_profile.

Install packages

  1. Command to install package in quiet mode ./CYGINSTALLER -P package_name -q (like ./setup-x86_64.exe -P git -q). Verify installation which package_name (like which git).

  2. You can install multiple packages by mentioning packages separated by comma ./CYGINSTALLER -P package1, package2, package3 -q.

uninstall packages

Command to uninstall package in quiet mode ./CYGINSTALLER -x package_name -q (like ./setup-x86_64.exe -x git -q).

Streamline the package installation

  1. Move to bin directory inside home directory cd ~/bin.

  2. Create a file name cyg touch cyg and open it in text editor.

  3. Copy and paste below code inside cyg file. Please replace CYGINSTALLER variable (setup-x86.exe or setup-x86_64.exe) as applicable for your system.

#!/bin/bash
CYGWIN_INSTALLER="CYGINSTALLER  --quiet-mode"
CYGWIN_SEARCH="cygcheck --package-query"
if [ $# -eq 0 ]; then
    $CYGWIN_INSTALLER --help
    exit 0
fi
case $1 in
    install )
    $CYGWIN_INSTALLER --packages $2
    ;;
    uninstall )
    $CYGWIN_INSTALLER --remove-packages $2
    ;;
    search )
    $CYGWIN_SEARCH $2
    ;;
    * )
    echo "USAGE: cyg [ install | uninstall | search ] package"
    exit 1
    ;;
esac
  1. You can install packages cyg install package_name.

  2. Uninstall packages cyg uninstall package_name.

  3. Package query cyg search package_name.

  4. Can do cygwin help cyg.

Debug

  • If you got error syntax error near unexpected token `$'in\r'' during running cyg command

    • Please got to ~/bin cd ~/bin directory and run this command sed -i 's/\r//' cyg