diff --git a/src/freedombone-app-xmpp b/src/freedombone-app-xmpp
index 0db02890e7135104499e49beb2c6b36846fd59d2..83c66eb9d3c011bfa503b313ff666c2544a3829b 100755
--- a/src/freedombone-app-xmpp
+++ b/src/freedombone-app-xmpp
@@ -788,9 +788,15 @@ function install_xmpp_main {
 
     apt-get -yq install lua-sec lua-bitop lua5.1 liblua5.1-dev
     apt-get -yq install libidn11-dev libssl-dev lua-dbi-sqlite3
+    rm -rf /tmp/*
     apt-get -yq mercurial
     apt-get -yq install prosody
 
+    if [ ! -f /usr/bin/hg ]; then
+        echo $"Couldn't install mercurial"
+        exit 52825
+    fi
+
     if [ ! -d /etc/prosody ]; then
         echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
         exit 52367