September 8, 2014

Getting the most out of Cygwin

A default install of Cygwin can feel very alien, even if you’re familiar with command-line Linux. Part of that is down to Cygwin’s not-great default integration with your Windows account. Another part of it is the dopey installer defaults which leave you with a half-crippled environment.

As you install Cygwin…

Choose the appropriate architecture

If you have a 64-bit machine, use the 64-bit installer. This will allow you to make the most of the memory on your machine.

Run the installer as Administrator

This is not obvious, but not doing it this way is the cause of many broken Cygwin installs.

Keep the setup defaults

Did I mention that Cygwin Setup is brittle? The rest of Cygwin is much smoother, I promise.

Choose some extra packages

Search for vim and check all the options you see.
 
Choose curl. Choose wget. Choose file. Choose openssh.

Don’t use the Irish mirror

It’s a dog. Pick one from a UK university instead.

After you’ve installed Cygwin…

Here’s what I always do after installing Cygwin for the first time on a new machine:

Edit the shortcut to mintty to make it a login shell

Find the Cygwin Terminal in your start menu and right-click it. Choose Properties’.
 
Charge the value of the argument to mintty.exe in Target’ as follows:
C:\cygwin\bin\mintty.exe -e /bin/bash --login
This change will cause the shell opened in the terminal program to be a login shell - which means your ~/.bash_profile file will always be read when you open a new terminal.

Make your home directory a symbolic link to c:<me>

Open a Cygwin shell. You’ll be in your Cygwin home directory, which has none of the familiar stuff you’d expect to see when you open Windows Explorer. We’ll fix that now.
 
Move all of the contents of your Cygwin home directory into your Windows home directory: 
$ _IFS=$IFS && IFS=$'\n' && mv $(find . -mindepth 1 -maxdepth 1) $(cygpath -u $USERPROFILE) ; IFS=$_IFS
Delete your now-empty Cygwin home directory and create a symbolic link with the same name pointing to your Windows home directory:
$ cd /home && rmdir $USER && ln -s $USERPROFILE $USER
Change directory back into your new home directory and start Windows Explorer:
$ cd ~ && explorer . &
Presto, you’ll see all your usual files! That means you can now use Cygwin to - for example - navigate to your Documents” folder with the command cd ~/Documents

Fix the colourful but wonky-looking default prompt

Using your favourite editor, open the file ~/.bash_profile. It may not exist; that’s OK, you can just create it.
 
If it doesn’t exist, add the following lines to it:
export PATH=$PATH:.:~/bin
PS1="[\u@\h:\w]$ "
If it does, just add the last line.
 
If you’re feeling a bit brave, you can try the following subtle but useful prompt instead:
PS1="[\[\033[01;37;1m\]\u@\h\[\033[00m\]:\[\033[01;37m\]\w\[\033[00m]]$"

Configure your corporate proxy in your bash environment

If you use a corporate proxy, use the following as a starting point. These settings go into your ~/.bash_profile:
export ftp_proxy=http://corpproxy:8080
export http_proxy=http://corpproxy:8080
export https_proxy=https://corpproxy:8080
export no_proxy="10.*, 192.168.*"
Remember that ~/.bash_profile is only read when your shell is started, so open a new terminal to get the changes.
 
Having the proxies set in your environment will allow lots of command-line tools that use the network to work properly: apt-cyg, youtube-dl, curl, wget, links and so on.

Install apt-cyg for command-line installation of Cygwin packages

As you’ve probably already noticed, the Cygwin installer is very clunky. I bypass it by using a tool that bears a passing similarity to Debian’s apt-get - it’s called apt-cyg.
 
If you need to use a proxy, follow the steps above, then follow these instructions to install apt-cyg.

Set up some useful aliases

Add these to your ~/.bash_profile:
alias ls='ls --color'
alias ll='ls -l'
 
 
 

Previous post
ISO 29119 is dead in the water The ISO are attempting to standardise testing, but there’s no consensus in the testing community. In particular: ‘An opponent of the
Next post
The state of Matrix The developers behind Matrix (in their own words, “An open network for secure, decentralized communication”) have recently published a post about a