Thursday, November 29, 2012

Cygwin package manager and auto updates

I use Cygwin on my Windows machine to get access to all the wonderful Linux tools like grep, wget, etc. One problem with Cygwin is you have to run it's GUI installer again manually each time you want to add tools or update the ones you already have.
apt-cyg provides a command-line package manager that you can use to install tools without using the GUI installer. However, I didn't see a way to update the existing tools. You can write a simple batch script to do the automatic updates for you. You only need the three lines below, assuming you've installed cygwin to C:\cygwin. Then, run the batch file as administrator or create a shortcut to do that for you.
cd C:\cygwin
wget -N http://cygwin.com/setup.exe
setup.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode
If you want to pretty it up so you can scan the results of the commands easier, just add some echo statements:
@ECHO off
cd C:\cygwin
echo ======================================
echo Downloading latest cygwin installer...
echo ======================================
echo.
wget -N http://cygwin.com/setup.exe
echo.
echo ======================================
echo Updating all cygwin packages...
echo ======================================
echo.
setup.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode
echo.
echo ======================================
echo Update finished.
echo ======================================
echo.
pause

5 comments:

  1. You probably found this out long ago, but in case anyone else finds this from a web search - you *can* upgrade from a cygwin terminal:-

    $ apt-get update
    $ for i in `apt-get show`; do apt-get install $i; done

    ReplyDelete
    Replies
    1. egremont2002, could you clarify this? As far as I know there is not an apt-get tool for cygwin.

      Delete
    2. It looks like a typo : use `apt-cyg` instead of `apt-get` and it works just fine indeed, though maybe a bit slower since it seems to restart the setup each time.

      Delete
    3. Update : to run the setup only once you could try the following command. Though it might not work with too many packages installed, there's a limit to the number of arguments on a command line, so it would be an issue with xargs.

      $ apt-cyg show | xargs apt-cyg install

      Delete
    4. @Michael that won't actually work - apt-cyg will skip any already installed packages. The only reliable way to upgrade a package is through the setup installer, or through a custom script.

      Delete