Skip to content

Instantly share code, notes, and snippets.

@dasginganinja
Last active November 14, 2023 15:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dasginganinja/1e958f8db5606974b6b8f65562343770 to your computer and use it in GitHub Desktop.
Save dasginganinja/1e958f8db5606974b6b8f65562343770 to your computer and use it in GitHub Desktop.
Install Unison 2.51.2 on Debian / Ubuntu - Used in Vagrant Guest Machines for compatibility with OSX Unison version
#!/bin/bash
apt-get update
apt-get install libdpkg-perl -y -f --allow-downgrades
apt-get install ocaml ocaml-native-compilers camlp4-extra opam -y -f
mkdir -p /usr/src/unison/
cd /usr/src/unison/
wget https://github.com/bcpierce00/unison/archive/refs/tags/v2.51.2.tar.gz -O unison.tar.gz
tar xzvf unison.tar.gz --strip-components 1
make UISTYLE=text || true
chmod +x unison unison-*
rm /usr/bin/unison
rm /usr/bin/unison-*
ln -s $PWD/unison /usr/bin/
ln -s $PWD/unison-* /usr/bin/
echo "fs.inotify.max_user_watches=262144" > /etc/sysctl.d/90-unison-notify.conf
sysctl -p --system
@markbil
Copy link

markbil commented Sep 9, 2019

this is very helpful, thank you! however, for unison to work properly, both client and server must not only have the same unison version installed, but it also needs to be compiled with the same version of OCaml on both ends. this is quite frustrating, as the ubuntu package manager currently only delivers OCaml 4.05.0, and my client runs unison version 2.51.2 (ocaml 4.08.1). how would you extend your script to install unison 2.51.2 on debian/ubuntu, but using the latest OCaml version 4.08.1? alternatively, any tipps on manual installation of OCaml 4.08.1 on ubuntu would be much appreciated as well. thank you!

@markbil
Copy link

markbil commented Sep 9, 2019

UPDATE for whom might be interested: I installed OCaml 4.08.1 from source, but the unison source code wouldn't compile if downloaded and extracted from https://www.seas.upenn.edu/~bcpierce/unison/download/releases/unison-2.51.2/unison-2.51.2.tar.gz. I ended up cloning unison from the official git repository https://github.com/bcpierce00/unison/ and then the installation went without a problem.

find instructions here: https://github.com/markbil/linux-insights/blob/master/unison_ocaml_installFromSource.md

thanks for the inspiration @dasginganinja.

@dasginganinja
Copy link
Author

Thanks for the update on that @markbil! I found that my instructions stopped working at one point and I went back to using polling-based watching because the fsmonitor was broken.

I'll take a look at your instructions. I'm going to match whatever version of ocaml the unison installed via brew has on the server side.

@dasginganinja
Copy link
Author

Here was the fix that I put in place (adapted from code from @markbil)

I ended up going with 4.07.0 since that is the current version returned by unison -version -- unison version 2.51.2 (ocaml 4.07.0).

4.07.1 ended up erroring out when make tags was ran by the unison Makefile.

  # Remove current references of oCaml
  apt purge ocaml
  rm -r /usr/bin/ocaml*

  # Remove current versions of unison binaries
  apt purge unison
  rm -r /usr/bin/unison
  rm -r /usr/bin/unison-*

  # Compile OCaml from source
  mkdir -p /usr/src/ocaml
  cd /usr/src/ocaml
  wget http://caml.inria.fr/pub/distrib/ocaml-4.07/ocaml-4.07.0.tar.gz
  tar xzvf ocaml-4.07.0.tar.gz --strip-components 1
  ./configure
  make world.opt
  make install
  make clean

  # Compile Unison from source
  rm -rf /usr/src/unison/
  mkdir -p /usr/src/unison/
  cd /usr/src/unison/
  wget https://www.seas.upenn.edu/~bcpierce/unison/download/releases/unison-2.51.2/unison-2.51.2.tar.gz -O unison.tar.gz
  tar xzvf unison.tar.gz  --strip-components 1
  make UISTYLE=text || true

  chmod +x unison unison-*
  ln -s $PWD/unison /usr/bin/
  ln -s $PWD/unison-* /usr/bin/

  unison -version

I'm sure I'll need to update the original install script at some point in the near future so I'll get a new revision in then. ;)

@Wedmal
Copy link

Wedmal commented Nov 10, 2023

@dasginganinja
Copy link
Author

@Wedmal Thank you -- updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment