diff --git a/src/freedombone-app-matrix b/src/freedombone-app-matrix
index fe31c1a644985148f07bece0d522690dd619b15a..68c3f71c1a53e7d332da8d1daa7da8eaa5554e7f 100755
--- a/src/freedombone-app-matrix
+++ b/src/freedombone-app-matrix
@@ -55,6 +55,9 @@ MATRIX_SECRET=
 MATRIX_EXPIRE_MONTHS=1
 MATRIX_MINIMUM_RAM_MB=1500
 
+MATRIX_PIP=pip
+MATRIX_PYTHON=python
+
 MATRIX_SHORT_DESCRIPTION=$'Chat system'
 MATRIX_DESCRIPTION=$'Chat system'
 MATRIX_MOBILE_APP_URL='https://f-droid.org/packages/im.vector.alpha'
@@ -240,11 +243,11 @@ function matrix_generate_homeserver_file {
     local filepath="${1}"
 
     cd /etc/matrix || exit 468246824
-    python -m synapse.app.homeserver \
-           --config-path "${filepath}" \
-           --generate-config \
-           --report-stats ${REPORT_STATS} \
-           --server-name ${MATRIX_DOMAIN_NAME}
+    $MATRIX_PYTHON -m synapse.app.homeserver \
+                   --config-path "${filepath}" \
+                   --generate-config \
+                   --report-stats ${REPORT_STATS} \
+                   --server-name ${MATRIX_DOMAIN_NAME}
 }
 
 function matrix_configure_homeserver_yaml {
@@ -445,20 +448,20 @@ function upgrade_matrix {
     fi
     export TMPDIR=/etc/matrix/tmp
 
-    pip install --upgrade --process-dependency-links .
-    pip install --upgrade --force "pynacl>=1.2.1"
+    $MATRIX_PIP install --upgrade --process-dependency-links .
+    $MATRIX_PIP install --upgrade --force "pynacl>=1.2.1"
 
     sed -i 's/ssl.PROTOCOL_SSLv23/ssl.PROTOCOL_TLSv1/g' /usr/local/bin/register_new_matrix_user
 
     chown -R matrix:matrix /etc/matrix
     chown -R matrix:matrix $MATRIX_DATA_DIR
 
-    pip install --upgrade --force "pynacl>=1.2.1"
-    pip install --upgrade --force "canonicaljson>=1.1.3"
-    pip install --upgrade --force "phonenumbers>=8.2.0"
-    pip install --upgrade --force "sortedcontainers>=2.0.4"
-    pip install --upgrade --force "prometheus_client>=0.3.0"
-    pip install --upgrade --force "treq>=15.1"
+    $MATRIX_PIP install --upgrade --force "pynacl>=1.2.1"
+    $MATRIX_PIP install --upgrade --force "canonicaljson>=1.1.3"
+    $MATRIX_PIP install --upgrade --force "phonenumbers>=8.2.0"
+    $MATRIX_PIP install --upgrade --force "sortedcontainers>=2.0.4"
+    $MATRIX_PIP install --upgrade --force "prometheus_client>=0.3.0"
+    $MATRIX_PIP install --upgrade --force "treq>=15.1"
 
     if [ -f /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.dhparam ]; then
         chmod 755 /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.dhparam
@@ -573,7 +576,7 @@ function remove_matrix {
     systemctl daemon-reload
     $REMOVE_PACKAGES_PURGE coturn
     cd /etc/matrix || exit 26472462
-    pip uninstall .
+    $MATRIX_PIP uninstall .
     rm -rf $MATRIX_DATA_DIR
     rm -rf /etc/matrix
 
@@ -618,10 +621,11 @@ function install_home_server {
         mkdir -p "$INSTALL_DIR/matrix"
     fi
     rm -rf /usr/local/lib/python2.7/dist-packages/ldap*
+    rm -rf /usr/local/lib/python3.5/dist-packages/ldap*
     if [ -d "$INSTALL_DIR/matrix" ]; then
         rm -rf "$INSTALL_DIR/matrix/"*
     fi
-    if ! pip install --upgrade --process-dependency-links . -b "$INSTALL_DIR/matrix"; then
+    if ! $MATRIX_PIP install --upgrade --process-dependency-links . -b "$INSTALL_DIR/matrix"; then
         echo $'Failed to install matrix home server'
         exit 782542
     fi
@@ -664,7 +668,7 @@ function install_home_server {
       echo 'Type=simple';
       echo 'User=matrix';
       echo "WorkingDirectory=/etc/matrix";
-      echo "ExecStart=/usr/bin/python -m synapse.app.homeserver --config-path ${MATRIX_DATA_DIR}/homeserver.yaml";
+      echo "ExecStart=/usr/bin/$MATRIX_PYTHON -m synapse.app.homeserver --config-path ${MATRIX_DATA_DIR}/homeserver.yaml";
       echo 'Restart=on-failure';
       echo 'RestartSec=10';
       echo '';
@@ -758,37 +762,38 @@ function install_matrix {
             libssl1.1 libtool libxml2 \
             libxml2-dev libxslt1-dev libxslt1.1 \
             make python python-dev \
-            python-pip python-psycopg2 \
+            python3 python3-dev python-pip python-psycopg2 \
+            python3-pip python3-psycopg2 python3-virtualenv \
             python-virtualenv sqlite unzip \
             zlib1g zlib1g-dev
 
     increment_app_install_progress
 
-    pip install --upgrade pip==9.0.3
+    $MATRIX_PIP install --upgrade pip==9.0.3
 
     increment_app_install_progress
 
-    pip install --upgrade python-ldap
+    $MATRIX_PIP install --upgrade python-ldap
 
     increment_app_install_progress
 
-    pip install --upgrade lxml
+    $MATRIX_PIP install --upgrade lxml
 
     increment_app_install_progress
 
-    pip install --upgrade --force "phonenumbers>=8.2.0"
+    $MATRIX_PIP install --upgrade --force "phonenumbers>=8.2.0"
 
     increment_app_install_progress
 
-    pip install --upgrade --force "sortedcontainers>=2.0.4"
+    $MATRIX_PIP install --upgrade --force "sortedcontainers>=2.0.4"
 
     increment_app_install_progress
 
-    pip install --upgrade --force "prometheus_client>=0.3.0"
+    $MATRIX_PIP install --upgrade --force "prometheus_client>=0.3.0"
 
     increment_app_install_progress
 
-    pip install --upgrade --force "treq>=15.1"
+    $MATRIX_PIP install --upgrade --force "treq>=15.1"
 
     increment_app_install_progress
 
@@ -822,11 +827,11 @@ function install_matrix {
 
     increment_app_install_progress
 
-    pip install --upgrade --force "pynacl>=1.2.1"
+    $MATRIX_PIP install --upgrade --force "pynacl>=1.2.1"
 
     increment_app_install_progress
 
-    pip install --upgrade --force "canonicaljson>=1.1.3"
+    $MATRIX_PIP install --upgrade --force "canonicaljson>=1.1.3"
 
     increment_app_install_progress