Install Solr on Ubuntu 16.04 together with Drupal


With these commands, you can install a Solr server, create a Solr core and copy the configuration files from the Drupal search_api_solr module to your Solr core.

# install required programs to install Java, do these one at a time ...
sudo apt-get install python-software-properties;
sudo add-apt-repository ppa:openjdk-r/ppa;
sudo apt-get update;
sudo apt-get install openjdk-8-jdk -y;
java -version;

cd /tmp;
# find latest Solr version at
# past versions at
tar xzf solr-6.6.5.tgz solr-6.6.5/bin/ --strip-components=2

# install Solr
sudo ./ solr-6.6.5.tgz

# NOTE: to upgrade from previous version of Solr, add -f parameter at the end, like this 
sudo ./ solr-6.6.5.tgz -f

# test: create and delete a Solr core
sudo su - solr -c "/opt/solr/bin/solr create -c test_delete -n data_driven_schema_configs"
sudo su - solr -c "/opt/solr/bin/solr delete -c test_delete"

# create a Solr core called "drupal"
sudo su - solr -c "/opt/solr/bin/solr create -c drupal -n data_driven_schema_configs"

# Drupal 8: copy config files from search_api_solr module
sudo cp -R /var/www/public/my_web_site/modules/contrib/search_api_solr/solr-conf/6.x/* /var/solr/data/drupal/conf

# Drupal 7: copy config files from search_api_solr module
sudo cp -R /var/www/public/my_web_site/sites/all/modules/search_api_solr/solr-conf/6.x/* /var/solr/data/drupal/conf

# NOTE: Very important, or some Solr files will be owned by root and not accessible 
sudo chown solr:solr -R /var/solr/data/;
sudo ls /var/solr/data/drupal/conf/ -l
sudo systemctl restart solr.service;

# check status
sudo systemctl status solr.service;

# access Solr via browser

# if you are using scotch box

# check version from terminal
wget http://localhost:8983/solr/admin/info/system?wt=json
cat system\?wt\=json

Completely uninstall an older version of Solr on Ubuntu 16.04

sudo service solr stop
sudo rm -r /var/solr
sudo rm -r /opt/solr-5.3.0
sudo rm -r /opt/solr
sudo rm /etc/init.d/solr
sudo deluser --remove-home solr
sudo deluser --group solr # doesn't seem to exist ...
sudo update-rc.d -f solr remove
sudo rm -rf /etc/default/