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 Name | Path in Windows | Path from Cygwin terminal |
CYGPATH | C:\cygwin or C:\cygwin64 | |
INSTALLERPATH | C:\cygwin_installer | /cygdrive/c/cygwin_installer |
CYGINSTALLER | setup-x86.exe or setup-x86_64.exe | setup-x86.exe or setup-x86_64.exe |
Open cygwin terminal from windows search box. Steps to directly access CYGINSTALLER from cygwin terminal.
Change current working directory to home directory
cd ~
.Create a bin directory inside home directory
mkdir bin
.Move to bin directory
cd ~/bin
.Create a softlink of cygwin installer inside bin directory
ln -s INSTALLERPATH/CYGINSTALLER
(use paths for cygwin terminal likeln -s /cygdrive/c/cygwin_installer/setup-x86_64.exe
).Verify the softlink created for CYGINSTALLER
ls -l
.Change current working directory to home directory
cd ~
.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
- Update the path
source .bash_profile
.
Install packages
Command to install package in quiet mode
./CYGINSTALLER -P package_name -q
(like./setup-x86_64.exe -P git -q
). Verify installationwhich package_name
(likewhich git
).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
Move to bin directory inside home directory
cd ~/bin
.Create a file name cyg
touch cyg
and open it in text editor.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
You can install packages
cyg install package_name
.Uninstall packages
cyg uninstall package_name
.Package query
cyg search package_name
.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 commandsed -i 's/\r//' cyg
- Please got to ~/bin