Unison is a great little tool to synchronize files between your local machine and a remote server. It’s free, open-source, and cross-platform. I use it every day to develop Jetpack. However, until very recently I couldn’t use it to work with files on this very site. I’m hosted with Webfaction, a great hosting provider for developers who want flexibility without having to deal with server administration. A lot of packages are already installed and configured on my server for me. Unison is not available by default, so I had to install it myself. Luckily, Webfaction lets you do that!
Before we get started, there are 2 important things to remember when setting up Unison:
– It has to be installed both locally and on the remote server.
– Both instances should use the same version of Unison.
Installing Unison locally is as easy as
brew install unison if you’re using Mac OSX. On your Webfaction server, it’s a bit trickier.
Since Unison was built using the OCaml language, you’ll need to install OCaml first.
I did everything in the
~/lib directory on my server.
$ wget http://caml.inria.fr/pub/distrib/ocaml-4.04/ocaml-4.04.0.tar.gz $ tar -zxvf ocaml-4.04.0.tar.gz $ rm ocaml-4.04.0.tar.gz $ cd ocaml-4.04.0 $ ./configure -prefix $HOME $ make world.opt $ make install
Once this was done, I checked the version of Unison running on my local machine:
$ unison -version unison version 2.48.4
$ cd ~/lib $ wget https://www.seas.upenn.edu/\~bcpierce/unison//download/releases/unison-2.48.4/unison-2.48.4.tar.gz $ tar -zxvf unison-2.48.4.tar.gz $ rm unison-2.48.4.tar.gz $ cd src $ make $ chmod a+x unison $ cp unison ~/bin
Try checking if Unison is installed by running
unison -version. It should return
unison version 2.48.4.
I then ran a few tests and synchronized 2 directories on the server; all worked fine. To do that quick test, create 2 folders,
test2. Add a random file in
test1. Then, run
unison test1 test2. You should see the random file you created get copied over to
test2 right away. Success!
But wait a second… When trying to synchronize a local directory with a directory on the server, Unison didn’t work. I kept getting this error:
zsh:1: command not found: unison Fatal error: Lost connection with the server
After some research, I found that since I installed Unison myself on Webfaction, the executable isn’t in the PATH for a non-interactive shell session. Luckily, Unison gives you 2 options to work around that:
– You can use the
servercmd parameter when launching Unison to pass the location of unison on to the remote server, like so:
$ unison -servercmd /home/username/bin/unison
– You can include that parameter in your Unison configuration file, like so:
servercmd = /home/username/bin/unison
And just like that, it works!