// Tutorial //

How To Install Solr 5.2.1 on Ubuntu 14.04

Published on July 14, 2015
Default avatar
By Koen Vlaswinkel
Developer and author at DigitalOcean.
How To Install Solr 5.2.1 on Ubuntu 14.04

Written in collaboration with Solr

Introduction

Solr is a search engine platform based on Apache Lucene. It is written in Java and uses the Lucene library to implement indexing. It can be accessed using a variety of REST APIs, including XML and JSON. This is the feature list from their website:

  • Advanced Full-Text Search Capabilities
  • Optimized for High Volume Web Traffic
  • Standards Based Open Interfaces - XML, JSON and HTTP
  • Comprehensive HTML Administration Interfaces
  • Server statistics exposed over JMX for monitoring
  • Linearly scalable, auto index replication, auto failover and recovery
  • Near Real-time indexing
  • Flexible and Adaptable with XML configuration
  • Extensible Plugin Architecture

In this article, we will install Solr using its binary distribution.

Prerequisites

To follow this tutorial, you will need:

Step 1 — Installing Java

Solr requires Java, so in this step, we will install it.

The complete Java installation process is thoroughly described in this article, but we’ll use a slightly different process.

First, use apt-get to install python-software-properties:

  1. sudo apt-get install python-software-properties

Instead of using the default-jdk or default-jre packages, we’ll install the latest version of Java 8. To do this, add the unofficial Java installer repository:

  1. sudo add-apt-repository ppa:webupd8team/java

You will need to press ENTER to accept adding the repository to your index.

Then, update the source list:

  1. sudo apt-get update

Last, install Java 8 using apt-get. You will need to agree to the Oracle Binary Code License Agreement for the Java SE Platform Products and JavaFX.

  1. sudo apt-get install oracle-java8-installer

Step 2 — Installing Solr

In this section, we will install Solr 5.2.1. We will begin by downloading the Solr distribution.

First, find a suitable mirror on this page. Then, copy the link of solr-5.2.1.tgz from the mirror. For example, we’ll use http://apache.mirror1.spango.com/lucene/solr/5.2.1/.

Then, download the file in your home directory:

  1. cd ~
  2. wget http://apache.mirror1.spango.com/lucene/solr/5.2.1/solr-5.2.1.tgz

Next, extract the service installation file:

  1. tar xzf solr-5.2.1.tgz solr-5.2.1/bin/install_solr_service.sh --strip-components=2

And install Solr as a service using the script:

  1. sudo bash ./install_solr_service.sh solr-5.2.1.tgz

Finally, check if the server is running:

  1. sudo service solr status

You should see an output that begins with this:

Solr status output
Found 1 Solr nodes: 

Solr process 2750 running on port 8983

. . .

Step 3 — Creating a Collection

In this section, we will create a simple Solr collection.

Solr can have multiple collections, but for this example, we will only use one. To create a new collection, use the following command. We run it as the Solr user in this case to avoid any permissions errors.

  1. sudo su - solr -c "/opt/solr/bin/solr create -c gettingstarted -n data_driven_schema_configs"

In this command, gettingstarted is the name of the collection and -n specifies the configset. There are 3 config sets supplied by Solr by default; in this case, we have used one that is schemaless, which means that any field can be supplied, with any name, and the type will be guessed.

You have now added the collection and can start adding data. The default schema has only one required field: id. It has no other default fields, only dynamic fields. If you want to have a look at the schema, where everything is explained clearly, have a look at the file /opt/solr/server/solr/gettingstarted/conf/schema.xml.

Step 4 — Adding and Querying Documents

In this section, we will explore the Solr web interface and add some documents to our collection.

When you visit http://your_server_ip:8983/solr using your web browser, the Solr web interface should appear:

Solr Web Interface

The web interface contains a lot of useful information which can be used to debug any problems you encounter during use.

Collections are divided up into cores, which is why there are a lot of references to cores in the web interface. Right now, the collection gettingstarted only contains one core, named gettingstarted. At the left-hand side, the Core Selector pull down menu is visible, in which you’ll be able to select gettingstarted to view more information.

After you’ve selected the gettingstarted core, select Documents. Documents store the real data that will be searchable by Solr. Because we have used a schemaless configuration, we can use any field. Let’sl add a single document with the following example JSON representation by copying the below into the Document(s) field:

{
    "number": 1,
    "president": "George Washington",
    "birth_year": 1732,
    "death_year": 1799,
    "took_office": "1789-04-30",
    "left_office": "1797-03-04",
    "party": "No Party"
}

Click Submit document to add the document to the index. After a few moments, you will see the following:

Output after adding Document
Status: success
Response:
{
  "responseHeader": {
    "status": 0,
    "QTime": 509
  }
}

You can add more documents, with a similar or a completely different structure, but you can also continue with just one document.

Now, select Query on the left to query the document we just added. With the default values in this screen, after clicking on Execute Query, you will see 10 documents at most, depending on how many you added:

Query output
{
  "responseHeader": {
    "status": 0,
    "QTime": 58,
    "params": {
      "q": "*:*",
      "indent": "true",
      "wt": "json",
      "_": "1436827539345"
    }
  },
  "response": {
    "numFound": 1,
    "start": 0,
    "docs": [
      {
        "number": [
          1
        ],
        "president": [
          "George Washington"
        ],
        "birth_year": [
          1732
        ],
        "death_year": [
          1799
        ],
        "took_office": [
          "1789-04-30T00:00:00Z"
        ],
        "left_office": [
          "1797-03-04T00:00:00Z"
        ],
        "party": [
          "No Party"
        ],
        "id": "1ce12ed2-add9-4c65-aeb4-a3c6efb1c5d1",
        "_version_": 1506622425947701200
      }
    ]
  }
}

Conclusion

There are many more options available, but you have now successfully installed Solr and can start using it for your own site.


Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up
About the authors
Default avatar
Developer and author at DigitalOcean.

Default avatar
senior technical writer

hi! i write do.co/docs now, but i used to be the senior tech editor publishing tutorials here in the community.


Still looking for an answer?

Was this helpful?
10 Comments

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Hey! I am a beginner at Solr. Now i have installed solr using a linux virtual machine on my windows laptop and its now running at http://Localhost:8983/solr. I need to know how do i get data into Solr from wikipedia database. I have the link to the data dumps

Thank you, How do I secure the solr web admin panel? Basically I have installed solr 6 on ubuntu 14. all went well but I could not find a way to secure the web panel. I have tried to add security.json in zookeeper but it always gives error connection refused on port 9983.

This worked great, but how do you recommend we secure this thing? Right now anyone can access this area and delete any cores that we may setup.

http://104.131.172.86:8983/solr/

HTTP ERROR 404

Problem accessing /solr/. Reason:

Not Found

Powered by Jetty:// why am not able to see the solr admin panel?

after installation am getting error root@dindudu:/opt# ls install_solr_service.sh solr-5.2.1.tgz root@dindudu:/opt# sudo bash ./install_solr_service.sh solr-5.2.1.tgz Extracting solr-5.2.1.tgz to /opt Creating /etc/init.d/solr script … System start/stop links for /etc/init.d/solr already exist. Waiting to see Solr listening on port 8983 [/] Still not seeing Solr listening on 8983 after 30 seconds! tail: cannot open ‘/var/solr/logs/solr.log’ for reading: No such file or directory

Found 1 Solr nodes:

Solr process 12410 from /var/solr/solr-8983.pid not found. Service solr installed. root@dindudu:/opt# sudo service solr status

Found 1 Solr nodes:

Solr process 12410 from /var/solr/solr-8983.pid not found. root@dindudu:/opt# service solr start Waiting to see Solr listening on port 8983 [/] Still not seeing Solr listening on 8983 after 30 seconds! tail: cannot open ‘/var/solr/logs/solr.log’ for reading: No such file or directory root@dindudu:/opt# /etc/init.d/solr status

Found 1 Solr nodes:

Solr process 12855 from /var/solr/solr-8983.pid not found. How to fix this error

Thank you.

Hi, I have installed the solr, it is running on the port 8983, but it shows this error new_core: org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: Could not load conf for core new_core: Error loading solr config from /var/solr/data/new_core/conf/solrconfig.xml… Could u help me to solve this error, Thanks in advance!

Having a similar issue to msahu. After install, going to http://[my.ip.add.ress]:8983/solr I see:

SolrCore Initialization Failures Please check your logs for more information [links] No cores available Go and create one… [links]

What am I doing wrong? “gettingstarted” exists in /var/solr/data…?

Thanks!