Setup XNAT on Ubuntu 16.04

  1. Create user xnat to run Tomcat service:
    sudo useradd -u 6667 -d /opt/xnat -s /bin/bash xnat
  2. Install PostgreSQL:
    sudo apt-get install postgresql
    then edit /etc/postgresql/9.5/main/postgresql.conf file:
    , and restart PostgreSQL server:
    sudo /etc/init.d/postgresql restart
  3. Install Java 7
    Current XNAT (v1.6.5) requires Java 7. Java 8 will NOT work. Type the commands below to install Java 7:
    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java7-installer oracle-java7-set-default
  4. Install Tomcat 7
    Current XNAT v1.6.5 requires Tomcat7. However, DO NOT install tomcat7 from Ubuntu Repository. It was compiled with Java 8 and will cause this problem. Instead, you should download from offical Tomcat web site. Type the command below to install tomcat:
    cd /opt
    sudo wget
    sudo tar zxvf apache-tomcat-7.0.70.tar.gz
    sudo ln -s /opt/apache-tomcat-7.0.70 /opt/tomcat7
    sudo chown -R xnat:xnat /opt/apache-tomcat-7.0.70
    sudo chown -R xnat:xnat /opt/tomcat7
    then set startup scripts permissions:
    sudo chmod +x /opt/tomcat7/bin/
    sudo chmod +x /opt/tomcat7/bin/
    and you need to set JAVA_OPTS in /opt/tomcat7/bin/ and insert the following line at the start:
    JAVA_OPTS="-XX:MaxPermSize=1024m -Xmx8192m"
    NOTE: you need to set MaxPermSize and MaxHeapSize(Xmx) in JAVA_OPTS. Otherwise, OutOfMemoryError will occur when you load XNAT web app.
  5. Install Maven:
    sudo apt-get install maven
  6. Download and extract XNAT 1.6.5:
    cd /opt
    sudo wget
    sudo tar zxvf xnat-1.6.5.tar.gz
    sudo chown -R xnat:xnat /opt/xnat
  7. Prepare XNAT directories:
    sudo mkdir /data/xnat/archive
    sudo mkdir /data/xnat/prearchive
    sudo mkdir /data/xnat/ftp
    sudo mkdir /data/xnat/cache
    sudo mkdir /data/xnat/build
    NOTE: '/data/xnat' should be the mount point for large storage for XNAT.
  8. Set up environment variables for xnat user, by editting .bashrc file:
    sudo su xnat
    vi ~/.bashrc
    add the following:
    # JAVA
    export JAVA_HOME=/usr/lib/jvm/java-7-oracle
    export PATH=$JAVA_HOME/bin:$PATH
    # Tomcat
    export TOMCAT_HOME=/opt/tomcat7
    export PATH=$PATH:$TOMCAT_HOME/bin
    # XNAT
    export XNAT_HOME=/opt/xnat
    export PATH=$PATH:$XNAT_HOME/bin
  9. Create XNAT database user xnat01:
    sudo su postgres
    createuser -U postgres -S -D -R -P xnat01
    Note: set and remember the password for db user xnat01, you will need it in the XNAT file.
  10. Create XNAT database:
    sudo su postgres
    createdb -U postgres -O xnat01 xnat
  11. Edit /opt/xnat/
    su xnat
    cd /opt/xnat
    and the content should be like below:
    maven.appserver.home = /opt/tomcat7
    Note: xdat.url need to be set to the public ip or address instead of localhost if you want the XNAT server to be accessed from other computers.
  12. Edit file. and replace the 'maven.repo.remote' line with

    NOTE: You need to do this because the offical XNAT maven repository is down.
  13. Run script to build:
    sudo su xnat
    cd /opt/xnat
  14. Create Database tables & views:
    cd /opt/xnat
    psql xnat01 -h localhost -d xnat -f deployments/xnat/sql/xnat.sql
    Note: you need supply the password for db user xnat01.
  15. Store initial security settings:
    sudo su xnat
    cd /opt/xnat/deployments/xnat
    StoreXML -project xnat -l security/security.xml -allowDataDeletion true
  16. Store Example Custom Variable Sets:
    sudo su xnat
    cd /opt/xnat/deployments/xnat
    StoreXML -dir ./work/field_groups -u admin -p admin -allowDataDeletion true
  17. Deploy the web app
    sudo su xnat
    cd /opt/xnat
    bin/ -Ddeploy=true
  18. Now start Tomcat7 server:
    sudo su xnat
  19. When open the xnat web page in browser the first name, it will take a very long time to load as it is loading the XNAT web app in Tomcat.

Key points

  • Install JAVA 7. Java 8 does not work.
  • Download Tomcat 7 binary from offical Tomcat web site. DO NOT install from Ubuntu Repository.
  • Set Java MaxPermSize and Xmx(MaxHeapSize) in JAVA_OPTS for Tomcat7 startup script Missing this step will cause OutOfMemoryError when load XNAT web app
  • Official XNAT maven repository site is down. Edit to replace it with
  • Tomat7 server is run as xnat user.

No comments:

Post a Comment